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

Validate event for Custom Validation

2 Answers 388 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Sindhura
Top achievements
Rank 1
Sindhura asked on 03 Mar 2016, 10:56 PM

How can I use "validate" Event (telerik doc) in Custom Validation?

Example code:

<script type="text/javascript">

//register custom validation rules

(function ($, kendo){

     $.extend(true, kendo.ui.validator, {

           rules: { // custom rules

                     productnamevalidation: function (input, params) {

                            if (input.is("[name='ProductName']") && input.val() != "") {

                                   input.attr("data-productnamevalidation-msg", "Product Name should start with capital letter");

                                   return /^[A-Z]/.test(input.val());

                           }

                           return true;

                    }    

          },

          messages: { //custom rules messages

                 productnamevalidation: function (input) {

                // return the message text

              return input.attr("data-val-productnamevalidation");}

            },

         validate: function (e){

              console.log(e.valid);

         }

       });

})(jQuery, kendo);

</script>

In the above code "e.valid" should return true if validation passed, false otherwise. My issue is that the validate event is never triggered on validation complete. Am I using this the right way? Please note that the above custom validation code is for grid custom editor templates. Not sure if the configuration has to be done differently in such cases.

Any help with this is appreciated.

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosen
Telerik team
answered on 07 Mar 2016, 09:47 AM

Hello Sindhura,

The code you have pasted is declaring a static rules which the Validator instance to use. It is not possible to attach event handles this way. They should be attached via the Validator instance. As you are using Grid, you should hook to its edit event there you can access the attached to the edit form Validator instance and attached the event handler. Similar to the following:

edit: function(e) {
   e.container.getKendoValidator().bind("validate", function(e) {
    console.log(e.valid);
  });
}

Regards,
Rosen
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Sindhura
Top achievements
Rank 1
answered on 07 Mar 2016, 09:16 PM
It works :) Thanks.
Tags
Validation
Asked by
Sindhura
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Sindhura
Top achievements
Rank 1
Share this question
or