This is a migrated thread and some comments may be shown as answers.

Remote Validation Similar to Unobtrusive jQuery Validation

1 Answer 176 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 23 Aug 2012, 01:35 PM
I was wondering if it is possible to use Kendo's Validation to achieve something similar to Microsoft's Unobtrussive ValidatIon:
http://weblogs.asp.net/jgalloway/archive/2012/03/23/asp-net-web-api-screencast-series-part-5-custom-validation.aspx 

In Kendo I can attach data attributes to my form fields in much the same way that I can with Unobtrussive Validation.  However with The latter, I can also do this:
$.validator.unobtrusive.revalidate(form, validationResult);

Which makes it possible to display server validations by building up a list of Field names and their associated errors.  Example of validationResult:
{"Author": "Author is too long! This was validated on the server."}

Is such a feature possible in Kendo?  If not, I could see it as a useful addition for the future.  We can validate 95% of what we need to do on the client, but something like this would be great for server validations such as checking for duplicates in the data store, etc.

1 Answer, 1 is accepted

Sort by
0
Jeff
Top achievements
Rank 1
answered on 23 Aug 2012, 02:11 PM
I think i figured this more or less figured out (at least in concept).

To handle this I think I would just need to create a custom Kendo validation rule something like this:

$("#myform").kendoValidator({
    rules: {
        remote: function(input){
            return $(input).data("remote-msg") != null;
        }
}

When the AJAX call fails, I'd then simply stick data-remote-msg attributes on the corresponding DOM elements, call kendo.validate, and then remove data-remote-msg from the various attributes (so I can call the server method again).

Haven't actually tried this yet, but I think it should work.
Tags
Validation
Asked by
Jeff
Top achievements
Rank 1
Answers by
Jeff
Top achievements
Rank 1
Share this question
or