Expand my Community achievements bar.

Who Me Too'd this topic

Avatar

Level 3

I have a touch ui dialog for my AEM component .In this dialog there is a special field (textfield) and I want to validate the value entered by calling a web service.

I use the below JavaScript to register a validator

(function($, window, document) {

       var registry = $(window).adaptTo("foundation-registry");

       registry.register("foundation.validation.validator", {

             selector : "[data-validation=name-validate]",

             validate : function(el) {

                    var element = $(el);

                    var elementVal = element.val();

                    $.get("webserviceURL", function(data) {

                          if (data.error) {

                                 return "Invalid name";

                          } else {

                                 return;

                          }

                    });

             }

       });

})($, window, document);

I can see that the server side call is happening but the validation is not happening in the dialog.

This is because the service call is asynchronous and the validate function get an empty return immediately.

So my question is how to do such server side validations?

Who Me Too'd this topic