Validate event for Custom Validation

3 posts, 1 answers
  1. Sindhura
    Sindhura avatar
    6 posts
    Member since:
    Apr 2014

    Posted 03 Mar Link to this post

    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. Answer
    Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 07 Mar Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Sindhura
    Sindhura avatar
    6 posts
    Member since:
    Apr 2014

    Posted 07 Mar in reply to Rosen Link to this post

    It works :) Thanks.
Back to Top