Ajax call inside validation rule

3 posts, 1 answers
  1. Answer
    A G
    A G avatar
    3 posts
    Member since:
    Dec 2005

    Posted 26 Mar 2013 Link to this post

       $("#myform").kendoValidator({

                rules:
                    {
       
                        json_rule: function (input) {
                            var ret = true;
                            if (input.is("[id=pwd]")) {
                                $.ajax({
                                    url: "api/HelperApi/Test" ,
                                    type: 'Get',
                                    data: { value: input.val() },
                                    success: function (result) {
                                        ret = result === true;
                                    }
                                });
                            }
                            return ret;
                        }

                    },

                messages: {

                    json_rule: "Json verified!",
        
           
                }
            });

    I never see the message for some reason (I verified the server call, it does return true and false)
  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 28 Mar 2013 Link to this post

    Hello,

    KendoUI validator is designed for performing a client-side validation. Remote validation is not supported at present.

    The reason your code is not working is that Ajax request is asynchronous. json_rule function will return the result before success event handler of the Ajax request is executed.

    Kind regards,
    Alexander Valchev
    the Telerik team
    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. A G
    A G avatar
    3 posts
    Member since:
    Dec 2005

    Posted 28 Mar 2013 Link to this post

    Thanks Alexander

    This works fine though when Ajax request is synchronous.

Back to Top