Forum
Calc Builder Support
Calc Builder supportForums
Public write access is disabled. Please login
Validate field greater or less than other field 17.09.2015 01:20
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
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
Re: Validate field greater or less than other field 17.09.2015 09:44
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[fldname=number1]").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,
Moonsoft Team
www.moonsoft.es
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[fldname=number1]").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,
Moonsoft Team
www.moonsoft.es
Re: Validate field greater or less than other field 16.11.2015 20:40
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[fldname=number1]").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[fldname=number1]").val();} }
});
Regards,
Moonsoft Team
www.moonsoft.es
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[fldname=number1]").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[fldname=number1]").val();} }
});
Regards,
Moonsoft Team
www.moonsoft.es
Re: Validate field greater or less than other field 17.11.2015 10:25
Hi,
Did you replace 'number1' for your field name (currentage)?
Regards,
Moonsoft Team
www.moonsoft.es
Did you replace 'number1' for your field name (currentage)?
Regards,
Moonsoft Team
www.moonsoft.es
Re: Validate field greater or less than other field 17.11.2015 10:57
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[fldname=deposit]").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[fldname=deposit]").val();} }
});
CB.validator.addMethod("cb_greaterthan", function(value, element, params) {
if (value=='') return false;
value=getNumber(value);
var valueinit=CB("input[fldname=deposit]").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[fldname=deposit]").val();} }
});
Re: Validate field greater or less than other field 17.11.2015 11:06
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,
Moonsoft Team
www.moonsoft.es
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,
Moonsoft Team
www.moonsoft.es