matbeard
Junior Member
Posts: 4
Registered: 2/20/2006
Member Is Offline
|
| posted on 5/9/2006 at 06:08 AM |
|
|
alter 'm' type validation for greater than
I'm tryin to add a new validation type that checks if a field is greater than another.
I've coped the code for checking for match, and changed it to this:
| Code: | //
check greater than
else if (this.a_fields[n_key]['g']) {
for (var n_key2 in this.a_fields)
if (n_key2 == this.a_fields[n_key]['g']) {
n_another = n_key2;
break;
}
if (n_another == null)
return this.f_alert(this.f_error(12, this.a_fields[n_key]));
if (this.a_fields[n_another]['v'] < this.a_fields[n_key]['v']) {
this.a_fields[n_key]['ml'] = this.a_fields[n_another]['l'];
this.a_fields[n_key].n_error = 13;
n_errors_count++;
}
} |
I've also added the appropriate error messages to the array.
I'm using 'g':'other field' in the constructor.
However, it's not working. Is there anything else I need to do?
Thanks
|
|
|
Hollstar
Member
Posts: 11
Registered: 4/4/2008
Location: Australia
Member Is Offline
|
| posted on 6/10/2008 at 11:30 PM |
|
|
Hi Mate,
I had much the same problem and had to write my own addition to this script. In my case, I had two drop down or select boxes allowing the user to
choose a min and max value from the list. Naturally, I wanted to ensure the minimum was less than or equal to its max.
I added the following lines to the JavaScript file:
| Code: |
// check less than or equal to
else if (this.a_fields[n_key]['<=']) {
for (var n_key2 in this.a_fields)
if (n_key2 == this.a_fields[n_key]['<=']) {
n_another = n_key2;
break;
}
// Debug:
//alert("n_another v: " + this.a_fields[n_another]['v'] + " n_key v: " + this.a_fields[n_key]['v']);
if (n_another == null)
return this.f_alert(this.f_error(6, this.a_fields[n_key]));
if (this.a_fields[n_key]['v'] > this.a_fields[n_another]['v']) {
this.a_fields[n_key]['ml'] = this.a_fields[n_another]['l'];
this.a_fields[n_key].n_error = 6;
n_errors_count++;
}
}
|
I also added this line to the a_messages array:
'The minimum for "%l%" must be less than or equal to its maximum'
This code works exactly the same way the password compare function does. Instead of using "m" however you use "<=" and then the field name
you're comparing. You of course also need to add the other field you're comparing to the script just as you do in the password compare example.
Good Luck! :)
|
|
|
Hollstar
Member
Posts: 11
Registered: 4/4/2008
Location: Australia
Member Is Offline
|
| posted on 6/10/2008 at 11:32 PM |
|
|
If you enable the debug I put in place, then compare it to your code, you will see where you went wrong...
Its all perfect except for one little thing! :)
|
|
|