Trongate Website Homepage

Success Animations

The mx-animate-success attribute in Trongate MX enables a visual success animation when an HTTP request returns a status code within the success range (i.e., between 200 and 299). This feature provides users with immediate visual feedback that an operation has completed successfully.

Important: Apply the mx-animate-success attribute to the element that initiates the HTTP request (e.g., a button or form). Placing it on unrelated elements will not trigger the success animation as intended.

Syntax

<element mx-animate-success="true">

The mx-animate-success attribute is a boolean attribute. Setting it to "true" activates the success animation for the specified element.

Usage

To use the mx-animate-success attribute:

  1. Add the mx-animate-success attribute to an element that triggers an AJAX request (e.g., a form with mx-post).
  2. Set the attribute value to "true" to enable the animation.
  3. When the AJAX request is successful, a checkmark animation will be displayed.

Note: The placement of the success animation is context-dependent:

  • Default Behavior: The animation appears in the location specified by the mx-target attribute.
  • Modal Exception: If the triggering element is within a modal body, the animation will be shown inside the modal body, overriding the mx-target setting.

Advanced Example

Here's a more comprehensive example demonstrating the use of the mx-animate-success attribute in a form, likely within a modal:

<form mx-post="title_boss/submit_attempt_add_item" 
      mx-close-on-success="true" 
      mx-animate-success="true" 
      mx-animate-error="true"
      mx-on-success="#result">
    <label>Item Title</label>
    <input type="text" name="item_title" placeholder="Enter title here..." autocomplete="off">
    <button type="submit">Submit</button>
<?= form_close() ?>

In this example:

To maximize the effectiveness of the mx-animate-success attribute, consider using it alongside other Trongate MX attributes as demonstrated in the example above:

  1. mx-animate-error: Handles error animations for failed requests.
  2. mx-close-on-success: Automatically closes modals on successful requests.
  3. mx-on-success: Triggers actions or updates elements after successful requests.

For a complete list of all Trongate MX attributes, check out our Trongate MX Attribute Reference.

Additional Notes

Using the mx-animate-success attribute, along with complementary attributes, allows you to create intuitive and responsive user interfaces in your Trongate MX applications, enhancing the overall user experience with visual feedback and automated actions.