validator.validate() giving wrong results

2 posts, 1 answers
  1. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 16 Apr 2015 Link to this post


     I will be referring to the following sample:


    The sample validates a textbox to have only 4 digits.

    When I enter wrong data, the validation message is shown. Then, I press "Save" button, validation message is gone + the validator.validate() says it is valid, while data is still wrong.

    Why do I need to call validate() method? Because, I offer the user a form with a Save button, so even if error messages are shown on page, I need to make sure things are valid before saving.

    Notice that, once validate() says the form is valid, now the textbox has the "k-valid" class. Hence, even if I enter wrong data again, the validation message won't be shown anymore!


    Appreciate your assistance.



  2. Answer
    Rosen avatar
    3253 posts

    Posted 17 Apr 2015 Link to this post

    Hi Bilal,

    This is caused by the fact that in the button click handler a new Kendo Validator instance is created and then this instance is validated. Instead, you should get the already existing Validator instance, similar to the following:

    $("button").on("click", function(e) {
      var validator1 = $("body").data("kendoValidator");

    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top