October CMS resources and help articles

Simple and to the point. Optimized by the community.

Tracking Changes to Form Behavior

3
by larryb, last modified on February 17th, 2020

Do you find yourself needing to alert your users when they attempt to leave a form that has changes on it? October make's it easy to do just that! This trick explains how you can enable input monitoring for your backend forms.

Assuming you have:

  1. Created your own plugin
  2. A controller with form behavior implemented
  3. Used default create and update partials

Instructions

  1. Navigate to the desired controller folder in your plugin directory (i.e. /plugins/author/plugin/controllers/controller)
  2. Open the desired partial (i.e. update.htm or create.htm)
  3. Modify the Form::open() statement with the following code:
<?= 
        Form::open([
            'class' => 'layout',
            'data-change-monitor' => 'data-change-monitor',
            'data-window-close-confirm'=>'There is unsaved data!'
        ]) 
    ?>
  1. Save the partial
  2. Visit the desired form behavior
  3. Make change to one of the fields
  4. Try to reload or leave the page
  5. Notice the alert indicating there are changes

You can repeat this process for additional forms and/or actions as desired

Discussion

0 comments

We use cookies to measure the performance of this website. Do you want to accept these cookies?