Validate validator on click.

4 posts, 1 answers
  1. XiMnet Malaysia
    XiMnet Malaysia avatar
    46 posts
    Member since:
    Jan 2006

    Posted 28 Oct 2014 Link to this post

    Hi, in this dojo, http://dojo.telerik.com/@ximnet/iciqu, I am trying to validate the form when the submit button is clicked.
    However I get error 'Uncaught TypeError: undefined is not a function'

    Is this the correct way to validate a validator?

    Thanks.


  2. Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 29 Oct 2014 Link to this post

    Hi,

    The error is thrown due to the fact that the form_validator variable is referencing the jQuery wrapped DOM element not the Validator widget, thus it does not have validate method. In order to get reference to the widget you may use the getKendoValidator method:

    var  form_validator = $("#form_reg").kendoValidator({
        rules: {
           /*..*/
        },
        messages: {
         /*..*/
        }
    }).getKendoValidator();

    Also note that as the Validator is attached to a form element, the validation will be executed automatically when the form is submitted, which in this case is when the button is clicked. Therefore, there is no need to manually call the validate method.

    If you want to execute some custom logic, for example show an alert to the user, when form is validated you may use the validate event.

    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. XiMnet Malaysia
    XiMnet Malaysia avatar
    46 posts
    Member since:
    Jan 2006

    Posted 30 Oct 2014 in reply to Rosen Link to this post

    Hi,

    I have updated my code with the validate event but it does not seems to fire the event when click on register button.
    http://dojo.telerik.com/@ximnet/iciqu

    When I try with a type="submit" button then it can work.

    Is there a way to make it work without specifying the button as submit type?

    Thanks





  5. Answer
    Rosen
    Admin
    Rosen avatar
    3237 posts

    Posted 31 Oct 2014 Link to this post

    Hello,

    As I have mentioned in my previous message, the automatic validation of the form will happen only when the form is submitted. In the sample you have provided the register button will not submit the form as it is not a submit button, therefore you will need to use the validate method to trigger the validation.

    Regards,
    Rosen
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready