FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
RSV Custom Validation - Match password
#1
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.



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(ferrorInfo){
        
// disabled all errors by default
        
for (var i=0i<myRules.lengthi++)        {
                var 
parts myRules[i].split(",");
                var 
fieldName parts[1];

                
document.getElementById(fieldName "_label").className "";
                
//document.getElementById(fieldName + "_error").style.display = "none";
        
}

        for (var 
i=0i<errorInfo.lengthi++)        {
                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({
                
onCompleteHandlermyOnComplete,
                
customErrorHandlermyCustomErrorDisplayFunction,
                
rulesmyRules
        
});
});[/
php 
]
Reply
#2
Hi,

Just a couple of quick thoughts. Have you actually tested using the same_as rule and found that it isn't working? I haven't had to use this rule myself yet, but thinking about how the rest of the validation works it doesn't matter that it is using the first fieldname (password) again as you can have multiple validation rules against one fieldname.

Rooting through the rsv.js file I found the following:

Code:
case "same_as":
        if (form[fieldName].value != form[fieldName2].value)
        {
          if (!rsv.processError(form[fieldName], errorMessage))
            return false;
        }
        break;

Which seems to suggest it will correctly compare the two values.

Hope that helps!

Martin
Reply
#3
Hi, there is nothing wrong with save_as. That part works. As I mention in my post, this is related to the placement of the field to check against. Since the fielDname is placed as the second value in the rule, the code actually highlights the first password field when the fields don't match. Is there another way to define the fieldnames?

//thanks
Reply
#4
(Mar 3rd, 2010, 1:20 AM)perfectpixel Wrote: Hi, there is nothing wrong with save_as. That part works. As I mention in my post, this is related to the placement of the field to check against. Since the fielDname is placed as the second value in the rule, the code actually highlights the first password field when the fields don't match. Is there another way to define the fieldnames?

//thanks
Sorry - I misunderstood. Aside from doing something clever so that the error formating is applied to the second value (guess this could be done in the script), the other route would be to define a custom validation rule (as shown in the docs), that would more flexibility.
Reply
#5
Hey guys,

Yeah - if I understand this properly, I think Martin's right: you'd probably need a custom rule to change the focus behaviour. I guess just switching rootpassword and rootpassword2 in the same_as rule wouldn't work?

But just so I'm totally clear: the problem is usability; you think that in the case of someone entering two different passwords should validate by always focusing on the FIRST password field? I gotta say, that sounds pretty reasonable to me... I wouldn't object to updating the script to behave like that.

- Ben
Reply
#6
Hi,

actually, the issue is with the way this example code has been constructed. The values In the rules are separated by commas and the script looks for the second value in each rule for the fieldnames. As such, the second value in the same_as rule is the same as the field to match against. The same_as rule should be applied in a different way, maybe like so same_as[fieldname] instead of same_as, fieldname.

Just a thought. As is, the custom example is flawed, since the second value in the same_as rule is the field to match against. Thus it won't return a rule that corresponds to the second field.





(Mar 7th, 2010, 11:21 AM)Ben Wrote: Hey guys,

Yeah - if I understand this properly, I think Martin's right: you'd probably need a custom rule to change the focus behaviour. I guess just switching rootpassword and rootpassword2 in the same_as rule wouldn't work?

But just so I'm totally clear: the problem is usability; you think that in the case of someone entering two different passwords should validate by always focusing on the FIRST password field? I gotta say, that sounds pretty reasonable to me... I wouldn't object to updating the script to behave like that.

- Ben
Reply
#7
Hey perfectpixel,

I'm sorry, I guess I'm just not following your explanation of the problem... Martin, if I'm being totally daft, do chime in.

Quote:As such, the second value in the same_as rule is the same as the field to match against.

No, I don't think so... the same_as rule works properly. I've actually used it for several years now and it still appears to be working fine.

Sorry for not following! Could you maybe post a link to the form so I could look at it directly?

- Ben
Reply
#8
The problem is here:

The custom validation gets the fieldname to validate from the second value of each rule (var fieldName = parts[1]; ) And if you look at the code below, the second value is the same for both rootpassword, and rootpassword2. The correct field would be rootpassword2 (marked in green below).

var myRules = [
"required,rootpassword,Password Required",
"same_as,rootpassword,rootpassword2,Password Must Match"
];

var parts = myRules[i].split(",");
var fieldName = parts[1];

Since the same_as function gets which field to match against from the variable placed right after it, after the comma (marked in red above), your example becomes flawed. The rule for the same_as line above will never return an error message for rootpassword2.

I think you have a great script, but I never got it to do what I wanted due to this issue. So I abandoned it. I'd love to use it, if the custom example is fixed Smile

Thanks!

(Mar 7th, 2010, 7:27 PM)Ben Wrote: Hey perfectpixel,

I'm sorry, I guess I'm just not following your explanation of the problem... Martin, if I'm being totally daft, do chime in.

Quote:As such, the second value in the same_as rule is the same as the field to match against.

No, I don't think so... the same_as rule works properly. I've actually used it for several years now and it still appears to be working fine.

Sorry for not following! Could you maybe post a link to the form so I could look at it directly?

- Ben
Reply
#9
Just interested in understanding the issue here. I've read this thread several times and I still can't see what the problem is!

The sameas rule compares (in the example you quote) rootpassword and rootpassword2. If rootpassword2 doesn't match rootpassword then the error message will be flagged against rootpassword. As mentioned above, if this is the issue you could create a custom rule that focuses on rootpassword2.

The format of the rule (ie second value in rule) doesn't overide the fact that rootpassword2 still gets tested. Provided your error message says 'both passwords must match' or something of that ilk, this will work perfectly from a user's perspective.


(Mar 7th, 2010, 11:11 PM)perfectpixel Wrote: The problem is here:

The custom validation gets the fieldname to validate from the second value of each rule (var fieldName = parts[1]; ) And if you look at the code below, the second value is the same for both rootpassword, and rootpassword2. The correct field would be rootpassword2 (marked in green below).

var myRules = [
"required,rootpassword,Password Required",
"same_as,rootpassword,rootpassword2,Password Must Match"
];

var parts = myRules[i].split(",");
var fieldName = parts[1];

Since the same_as function gets which field to match against from the variable placed right after it, after the comma (marked in red above), your example becomes flawed. The rule for the same_as line above will never return an error message for rootpassword2.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)