Open bewards opened 8 years ago
The object sent to addValidator
is sent by reference and as a consequence, you can change the value of errorMessage
in runtime.
$.formUtils.addValidator({
...
validatorFunction: function() {
if (likeThis()) {
this.errorMessage = "It's like this...";
return false;
} else if (likeThat()) {
this.errorMessage = "It's like that...";
return false;
} else {
return true;
}
},
errorMessage: '' // will change in runtime...
})
Good to know! This can be closed. I'll reply if anything goes wrong.
Added a small custom validator, called different_input_value, to compare the current inputs value against an input in the same form (could extend this to multiple inputs that just have the data attribute without an attr value) to make sure they are not the same. I didn't see an existing validator for this. I would like to change the errorMessage to dynamically display the two inputs placeholder values like so:
"[Secondary Email] must have a different value from [Primary Email]"
Given the following inputs:
js validator
There may currently be a way to add logic for this in an error callback event, but what if the
errorMessage
property supported a callback that passed in the $el and the effected input? If there's something already available that I can do, we can just scratch this idea :wink: