Remote Validation Similar to Unobtrusive jQuery Validation

2 posts, 0 answers
  1. Jeff
    Jeff avatar
    66 posts
    Member since:
    May 2005

    Posted 23 Aug 2012 Link to this post

    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.
  2. Jeff
    Jeff avatar
    66 posts
    Member since:
    May 2005

    Posted 23 Aug 2012 Link to this post

    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.
  3. Kendo UI is VS 2017 Ready
Back to Top