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

validator.validate() giving wrong results

1 Answer 476 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Bilal
Top achievements
Rank 2
Bilal asked on 16 Apr 2015, 11:44 PM

Hi,

 I will be referring to the following sample: http://dojo.telerik.com/@bhaidar/EYUFu

 

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.

 

Regards
Bilal

1 Answer, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 17 Apr 2015, 08:50 AM
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");
  console.log(validator1);
  //....
});


Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Validation
Asked by
Bilal
Top achievements
Rank 2
Answers by
Rosen
Telerik team
Share this question
or