Validate Touch UI dialog field with a server side call

Avatar

Avatar

dennyj13354090

Avatar

dennyj13354090

dennyj13354090

15-05-2019

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?

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883
Arun_Patidar
MVP

15-05-2019

try validation with jquery like below thread and make sync call

Adding multifields based on numberfield in AEM 6.4

e.g.

jQuery.ajax({
  url
: 'http://example.com/catalog/create/' + targetNode.id + '?name=' + encode(to.inp[0].value),
  success
: function (result) {
  
if (result.isOk == false) alert(result.message);
  
},
  
async: false
  
});

Answers (3)

Answers (3)

Avatar

Avatar

dennyj13354090

Avatar

dennyj13354090

dennyj13354090

16-05-2019

Thank you very much.

Avatar

Avatar

dennyj13354090

Avatar

dennyj13354090

dennyj13354090

15-05-2019

On dialog submit

Avatar

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883

Avatar

Arun_Patidar

MVP

Total Posts

3.1K

Likes

1.2K

Correct Reply

883
Arun_Patidar
MVP

15-05-2019

Hi,

When are you calling web service? On load? on dialog submit or on input field blur event.