Hi,
yes, the module includes the jquery validator, so you can extend the default validations adding any custom functions. In order to add a new validation 'this field must be greater than 'number1' field', this is the code you should add to the first javascript tab of the calculator 'executed on loaded page':
CB.validator.addMethod("cb_greaterthan", function(value, element, params) {
if (value=='') return false;
value=getNumber(value);
//Replace here 'number1' for your field name (currentage)
var valueinit=CB("input").val();
valueinit=getNumber(valueinit);
return value>valueinit;
//Replace here the message for the preferred one
}, CB.validator.format("Value must be greater than number1"));
CB.validator.addClassRules({
cb_greaterthan : { cb_greaterthan : true }
});
Just replace 'number1' for your field name (currentage). Now you can add this validation to the second field (retiring age), this is done at the 'field configuration'. Add
cb_greaterthan
to its 'Css class' field.
Hope this helps,
Thanks,
It helped a lot.
Hi i need that the number 1 in the message up there to be the variable data itself ??
Hi i need that the number 1 in the message up there to be the variable data itself ??
Hi,
You could add variable to message changing message format and class rules like this:
CB.validator.addMethod("cb_greaterthan", function(value, element, params) {
if (value=='') return false;
value=getNumber(value);
//Replace here 'number1' for your field name (currentage)
var valueinit=CB("input").val();
valueinit=getNumber(valueinit);
return value>valueinit;
//Replace here the message for the preferred one
}, CB.validator.format("Value must be greater than {0}"));
CB.validator.addClassRules({
cb_greaterthan : { cb_greaterthan : function(){return CB("input").val();} }
});
Regards,
Thank You. But it doesn't display any messages at all.
Hi,
Did you replace 'number1' for your field name (currentage)?
Regards,
yes i did. It is named "deposit" in my case.
CB.validator.addMethod("cb_greaterthan", function(value, element, params) {
if (value=='') return false;
value=getNumber(value);
var valueinit=CB("input").val();
valueinit=getNumber(valueinit);
return value>=valueinit;
}, CB.validator.format("Value must be greater than {0}"));
CB.validator.addClassRules({
cb_greaterthan : { cb_greaterthan : function(){return CB("input").val();} }
});
Hi,
With this code and setting 'cb_greaterthan' class in the other field, should be work. Please export your calculator and place a private helpdesk ticket and we'll take a look.
Regards,
Hi,
I have a form with some number fields in it. I need to validate the field value based on the value of the other field.
For instance, retiring age should be greater than current age.
Is that possible? If yes, how can I do it?
Thanks in advance