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

Ajax call inside validation rule

3 Answers 208 Views
Validation
This is a migrated thread and some comments may be shown as answers.
A G
Top achievements
Rank 1
A G asked on 26 Mar 2013, 08:24 PM
   $("#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)

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 28 Mar 2013, 08:22 AM
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!
0
A G
Top achievements
Rank 1
answered on 28 Mar 2013, 02:37 PM
Thanks Alexander

This works fine though when Ajax request is synchronous.

0
Will
Top achievements
Rank 1
answered on 21 Mar 2019, 01:07 PM

Just for anyone else passing this way, there is a rather involved solution provided in detail here:

https://www.telerik.com/blogs/extending-the-kendo-ui-validator-with-custom-rules

 

Tags
Validation
Asked by
A G
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
A G
Top achievements
Rank 1
Will
Top achievements
Rank 1
Share this question
or