Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Field validation that calls a service

Avatar

Level 1

Looking to apply custom validation via the rule editor that calls a service based on some values. I've been able to configure this via the editor, during form validation I see the call to the service being made but this call has no influence over the validation response. It appears that the validation does not wait for the promise to complete.

 

Is it possible to have the validation rule editor wait for a response from a call and use that to determine if the field is actually valid or not?

0 Replies

Avatar

Employee Advisor

@byhi 

We provide multiple options[0] to handle validations OOTB with AEM Forms.

Also for the case at hand, you can use the code editor[1] (NOT the visual editor) to add an additional check for the response/ loop to verify the response and process the data further.

 

[0] - https://experienceleague.adobe.com/docs/experience-manager-64/forms/adaptive-forms-advanced-authorin... 

 

[1] - https://experienceleague.adobe.com/docs/experience-manager-65/forms/adaptive-forms-advanced-authorin... 

Avatar

Level 1

Thank you @Pulkit_Jain_ 

I have followed the documentation and created custom functions for validation. The challenge is, the rule editor/validation service is not respecting what my function is returning. For example, this custom validate function:

function validate() {
  return somePromise().then(function (promiseResponse) {
    return $.ajax({
      url: '/service/url',
      method: "POST",
      data: "data=" + promiseResponse
    }).then(function (response) {
      return response.success
    }).catch(function () {
      return false;
    });
  });
}

The form validation is not respecting the function's return, when the function returns false, the form still says it is valid. The function does run, but I've noticed that the validation feedback is presented to the user before the function/request has occurred/completed.

Avatar

Level 10

@byhi change 

 return response.success

to

 

 response.success

 

no return is required.