Mar 2nd, 2010, 2:35 PM
Hi,
I am using the RSV method to validate 3 fields. But I am having an issue with the way the code finds the form fields.
The code below splits the values for each rule in myRules, (se var parts), then gets the fieldnames based on the second item in each rule. Now, when I try to use 'same_as' for my second password field 'rootpassword2', I have to specify 'rootpassword' as the second item in the rule:
var myRules = [
"required,hostname,Host Name Required",
"required,rootpassword,Password Required",
"same_as,rootpassword,rootpassword2,Password Must Match"
];
The problem is that the code...
var parts = myRules[i].split(",");
var fieldName = parts[1];
... uses the second value in the rule, bypassing the actual fieldname 'rootpassword2'.
Any help you can provide to fix the issue is greatly appreciated.
]
I am using the RSV method to validate 3 fields. But I am having an issue with the way the code finds the form fields.
The code below splits the values for each rule in myRules, (se var parts), then gets the fieldnames based on the second item in each rule. Now, when I try to use 'same_as' for my second password field 'rootpassword2', I have to specify 'rootpassword' as the second item in the rule:
var myRules = [
"required,hostname,Host Name Required",
"required,rootpassword,Password Required",
"same_as,rootpassword,rootpassword2,Password Must Match"
];
The problem is that the code...
var parts = myRules[i].split(",");
var fieldName = parts[1];
... uses the second value in the rule, bypassing the actual fieldname 'rootpassword2'.
Any help you can provide to fix the issue is greatly appreciated.
PHP Code:
jQuery.noConflict();
// a custom onComplete handler to prevent form submits for the demo
function myOnComplete() {
alert("The form validates!");
return false;
}
/**
* My custom error message handler. This displays each error message next to
* each field. It assumes there are hidden fields
*/
function myCustomErrorDisplayFunction(f, errorInfo){
// disabled all errors by default
for (var i=0; i<myRules.length; i++) {
var parts = myRules[i].split(",");
var fieldName = parts[1];
document.getElementById(fieldName + "_label").className = "";
//document.getElementById(fieldName + "_error").style.display = "none";
}
for (var i=0; i<errorInfo.length; i++) {
var fieldName;
// radio button
if (errorInfo[i][0].type == undefined)
fieldName = errorInfo[i][0][0].name;
else
fieldName = errorInfo[i][0].name;
// display the error
document.getElementById(fieldName + "_label").className = "sa-hot";
//document.getElementById(fieldName + "_error").style.display = "block";
// document.getElementById(fieldName + "_error").innerHTML = errorInfo[i][1];
}
// normally, we'd do something like this: only return TRUE if there were no errors.
// but this is just a demo. so it's commented out.
//return (errorInfo.length == 0) ? true : false;
if (errorInfo.length == 0)
alert("Form submitted here!");
return false;
}
var myRules = [
"required,hostname,Host Name Required",
"required,rootpassword,Password Required",
"same_as,rootpassword,rootpassword2,Password Must Match"
];
jQuery(document).ready(function() {
jQuery("#sa_form").RSV({
onCompleteHandler: myOnComplete,
customErrorHandler: myCustomErrorDisplayFunction,
rules: myRules
});
});[/php