Tracking Changes to Form Behavior
3
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:
- Created your own plugin
- A controller with form behavior implemented
- Used default create and update partials
Instructions
- Navigate to the desired controller folder in your plugin directory (i.e. /plugins/author/plugin/controllers/controller)
- Open the desired partial (i.e. update.htm or create.htm)
- 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!'
])
?>
- Save the partial
- Visit the desired form behavior
- Make change to one of the fields
- Try to reload or leave the page
- Notice the alert indicating there are changes
You can repeat this process for additional forms and/or actions as desired
This does not seem to monitor date changes from the date widget (OCMS2).