The documentation is a bit spare on how custom rules should be handled in Validator. E.g., I am assuming that if you have multiple custom rules, they are all handled via decision trees in the "custom" configuration object. And if that is true, then I am assuming you have to do the same for the "message" configuration object if you want to have a different message for each custom rule.
However, it is not clear in the documentation how one should send the specific message text.
E.g., let's say we want to have two custom rules.
The above code is for illustration and has not been actually tested.
However, I do know that the line
My hunch is that there is a specific formatting function that must be used. Any hints or leads, here, for what that might be?
TIA
However, it is not clear in the documentation how one should send the specific message text.
E.g., let's say we want to have two custom rules.
- One rule checks the "firstname" input field and fails if the value does not include "Tom". On failure, we want the message for that field to be "Please be a Tom".
- The other rule checks the "lastname" input field and fails if the value does not include "Smith". On failure, we want the message for that field to be "Please be a Smith".
$(
"#myform"
).kendoValidator({
rules: {
custom:
function
(input) {
var
ret =
true
;
if
(input.is(
"[name=firstname]"
)){
ret = (input.val() ===
"Tom"
);
}
else
if
(input.is(
"[name=lastname]"
)){
ret = (input.val() ===
"Smith"
);
}
return
ret;
}
},
messages: {
custom:
function
(input) {
if
( input.is("[name=firstname]") ) {
// want the message to say "Please be Tom"
return
'Please be a Tom'
;
// this does not work
}
else
if
( input.is(["name=lastname]") ) {
// want the message to say "Please be Tom"
return
'Please be a Smith'
;
// this does not work
}
}
}
});
The above code is for illustration and has not been actually tested.
However, I do know that the line
return
'Please be Tom'
;
fails to place any text in the error message.My hunch is that there is a specific formatting function that must be used. Any hints or leads, here, for what that might be?
TIA