We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Custom Validation Method Async

Hi,

I need an example on how to use an ajax async request inside an "addMethod" call from the grid component.

$.validator.addMethod("myFunction", function (value, element, params) {

            $.ajax({
                type: "GET",
                url: 'MyFunction',
                ...
                },
                success: function (data) {
                   return 
                }
            });
        }, "Error"); 
    });

With this code, the validator returns false before the ajax request completes. I did it this way instead of using the "remote" ValidationRule because I need to pass two parameters to the function on the server. If there is a better solution to this, please let me know.


Thank you.

5 Replies

TS Thavasianand Sankaranarayanan Syncfusion Team July 5, 2019 09:27 AM UTC

Hi Erik, 

Greetings from Syncfusion support. 

Before proceeding to your query please provide whether you have using EJ 1 Grid component or EJ 2 Grid component in your application. Based on your confirmation we can provide better assistance on your requirement. 

Regards, 
Thavasianand S. 



ER Erik July 5, 2019 11:01 AM UTC

Hi Thavasianand,

I'm using the EJ 1 Grid component.


Regards,


FS Farveen Sulthana Thameeztheen Basha Syncfusion Team July 8, 2019 09:39 AM UTC

Hi Erik 

Thanks for contacting Syncfusion Support. 

Query:-  I did it this way instead of using the "remote" ValidationRule because I need to pass two parameters to the function on the server. If there is a better solution to this, please let me know. 
 
We have checked your query and we have already discussed in our syncfusion knowledge base  about how to perform serverside validation on server side. From this you can pass the required values to serverend through ajax post and perform validation on it.  
 
For your convenience, refer to the KB link:- 

Please get back to us if you need any further assistance. 

Regards, 
Farveen sulthana T 



ER Erik July 11, 2019 04:31 PM UTC

Hello Farveen.

Thank you very much. That worked perfectly.


Regards.



FS Farveen Sulthana Thameeztheen Basha Syncfusion Team July 12, 2019 10:36 AM UTC

  
Hi Erik, 

Thanks for your update. Please get back to us if you need any further assistance. 

Regards, 

Farveen sulthana T 


Loader.
Live Chat Icon For mobile
Up arrow icon