JS can track which field has been just changed. So if you could prevent default submission of the form like this:
<cms:form .... onSubmit="javascript:compare()" >
Then use a js function which I called 'compare', in which do the comparison for a single field first (adding in a loop after this proof of concept).
For text fields:
// text input: my_textfield
- Code: Select all
var t = document.getElementById('f_my_textfield');
if( t && (t.value != t.defaultValue) ){
/* .. field has been changed */ alert('text changed!');
}
For checkboxes
// checkbox input: my_checkbox
- Code: Select all
var ch = document.getElementById('f_my_checkbox');
if ( ch && (ch.checked != ch.defaultChecked) ){
/* .. field has been changed */ alert('checkbox changed!');
}
And finally, submit the form. for example
document.getElementById("edit-form").submit();
This might work. I once had to do it for 200 fields and they were named like field_1_text, ... field_199_text - so I put a simple loop:
- Code: Select all
for( var i=1; i<=200; i++ ){
var t = document.getElementById('f_field_'+i+'_text');
if( t && (t.value != t.defaultValue) ){
... field changed, do something ..
}
}
Maybe there are other simpler solutions, idk.
The idea behind it is very simple - there are no comparisons with stored data in database. Only reported fields are those that user has inputted/changed/erased data and submitted. Fields that were changed and then reverted without submission are not reported - so, if user types in something and then erases it before submit - that field will not have the flag 'changed' set by browser.
A little note to speed up understanding:
defaultChecked and
defaultValue are properties of the inputs, not my variables. And also Couch adds an id automatically to each input and adds
f_ to its name.