I have a form generated by <% Ajax.BeginForm() {} %>
which contains a lot of inputs and texareas.
When an input value change, I need to know about it and mark the input and the form as "dirty". If the user tries to leave the page without saving, I will ask him or her to confirm abandoning changes.
Any suggestion to how this should be done?
$("#myform"). trackChanges(); and check if a form has changed: if ($("#myform").
You can easily reset all form values using the HTML button using <input type=”reset”> attribute. Clicking the reset button restores the form to its original state (the default value) before the user started entering values into the fields, selecting radio buttons, checkboxes, etc.
Yes. More, it is essential if you are dealing with radio button groups.
Resurrecting this old question because I thought of a simpler/better way. Instead of listening to events on the various inputs, you can serialize the initial form data, store it, and then serialize it again later and check if it's changed, like this:
var originalFormData = $('form#formId').serialize(); function checkFormChanged() { if(originalFormData !== $('form#formId').serialize()) { //it's dirty! } }
One additional advantage here is that if the user makes a change and then reverts it, this check will report the form as clean.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With