We have a kendo Grid, and then we have an editor template, which is named after the view model.
Inside the viewModel we have this:
[Required( ErrorMessage = "Please enter a name")]
public string Name{ get; set; }
Then inside the javascript, I create another custom rule like this :
var form = $("#AdhocGroupForm")
form.kendoValidator({
messages: {
nameexists: "This name already exists, please choose another"
},
rules: {
nameexists: function(input) {
if (input.is("[name=Name]")) {
return input.val() === "Tom";
}
return true;
}
}
});
Of course, this does nothing right now. I'm simply trying to set this up and get to the point where it's called, then I'll flesh it out to check if the provided name exists, via AJAX. However, it's not called, and that is part of the issue.
The other part is that when I do this:
var validator = $("#AdhocGroupForm").kendoValidator().data("kendoValidator");
I expect to get an object that I can call 'validate' on ( I assume this is what I need to do to trigger validation although some things I've seen make me think it will fire on each keypress ). However, this returns null. kendoValidator() returns an object, but this has no validate method, either. I believe this is my core issue, I don't have a validator to work with.The form and textbox html in my page looks like this:
<form action="/AdhocGroup/AdhocGroupForm/AdhocGroupForm" data-role="validator" method="post" novalidate="novalidate">
<input class="input k-textbox" data-val="true" data-val-nameexists="data-val-nameexists" data-val-required="Please enter a name" id="Name" name="Name" style="width: 200px;" type="text" value="" data-bind="value:Name">
The validation for the required field, with my custom error message, works fine.This is my first day using these validators, so it's possible I've missed something obvious. Thanks for any advice.