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

Validation Studying

1 Answer 49 Views
Validation
This is a migrated thread and some comments may be shown as answers.
Chenkai
Top achievements
Rank 1
Chenkai asked on 20 May 2014, 01:24 AM

At first, Thanks for kendo. it is used conveniently. but there are some ways I can't understand or I think it's not elegant.

1. $("#temp").kendoValidator().data("kendoValidator").validate() doesn't validate rules which I specify.
I add my rules in Validation to validate password and confirm password. when element loses focus, fantastic!!!! It does work. I really happily continue coding.

if( !$("#temp").kendoValidator().data("kendoValidator").validate() ){
     return false;
}
when I submit data with AJAX. Oh no.. break down because I write different password in password input and confirm Password input. I realize that validate() don't use rules. I don't know why?  The only reason I can find is rules need know the real <input> widget.

2. form submit.
I don't find some solutions. So I return to use form submit which likes:
<form>
    <input name="username" required /> <br />
    <button id="save">Save</button>
  </form>
 
  <script>
    // attach a validator to the container
    $("form").kendoValidator({
        validate: function(e) {
            console.log("valid" + e.valid);
        }
    });
  </script>
it works. when I submit, e.valid validates rules. but it refresh web. Oh no, I don't want the way refreshes my web because I want to make SPA with AJAX. So I add onsubmit="return false" in <form>. but I think it is not elegant. I don't like it. If kendo can integrate these. it will be brilliant and elegant.


Best regards. 


1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 20 May 2014, 01:11 PM
Hi Chenkai,

Regarding your issues:

1. The issue occurs because you are re-initializing the validator with empty settings.
$("#temp") //select element
  //.kendoValidator() //initialize validator
  .data("kendoValidator") //get validator client side object
  .validate() //call the method

Removing the code marked in red should resolve the problem.

2. Your question is not directly related to Kendo UI but to general programming knowledge about "how to submit forms with jQuery.ajax". There are a lot of tutorial on the internet which explain in steps how this can be done (here is one example). Please search the web for a tutorial related to the server side platform you are using.

Regards,
Alexander Valchev
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
Chenkai
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or