Stopping execution of Prototype.js Dexagogo validation
March 25th, 2008
Nice how I try and stop validation on the two main javascript libraries one day after another.
Dexagogo Validation ala prototype.js is a little less awkward from my tests; partially because Tetlaw actually says how to trigger validation manually.
Due to the lower standard of code for this job, “noValidate” is attached to onClick events elsewhere.
function valid (e) {
var doit = new Validation(document.forms[0],{submit: false, immediate: false});
if ( !doit.validate() ) {
Event.stop(e);
}
};
Event.observe(document.forms[0], ’submit’, valid, false);
function noValidate(evt) {
Event.stopObserving(document.forms[0], ’submit’, valid);
}
One caveat: once the form has failed validation (a non-noValidate submit), noValidate fails to work. I can only figure this as a side effect of somthing in prototype 1.5 (as I said, lower standard of code), as Tetlaw’s code doesn’t seem to bind anywhere else.
Posted in JavaScript |