Custom equality comparison
Custom equality comparison
sliekens
Posts: 97Questions: 17Answers: 2
With Editor, when you submit a form without changing any fields, Editor is smart enough to not submit the data. This is great, but I'd like more control over how Editor decides when values are changed.
I suggest introducing a field.changeDetection
callback function that Editor can invoke with the old and the new field value when submitting a form.
changeDetection: function(oldValue, newValue) {
// returns true to indicate a change is detected; otherwise, false
}
Example usage:
var editor = new $.fn.Editor( {
ajax: "php/staff.php",
table: "#myTable",
fields: [
{
label: "First name:",
name: "first_name",
changeDetection: function(oldValue, newValue) {
if (oldValue.trim() === newValue.trim()) {
// unchanged
return false;
} else {
return true;
}
}
}
]
} );
Example usage 2:
// treat empty strings and white space as null
function changeDetection(oldValue, newValue) {
if (oldValue == null && newValue.trim() === '') {
return false;
} else {
return newValue !== oldValue;
}
}
}
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Thanks for the suggestion. This might have been useful in another recent thread where loose type checking was wanted rather than strict.
I've added it to my list of future features.
Regards,
Allan
Just to say that Editor 1.7 will have a
fields.compare
option which can be used to determine if the field should be submitted to the server or not.Regards,
Allan