Field validation that calls a service | Community
Skip to main content
New Participant
April 26, 2022

Field validation that calls a service

  • April 26, 2022
  • 2 replies
  • 746 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Mayank_Gandhi
Employee
May 2, 2022

@byhi change 

 return response.success

to

 

 response.success

 

no return is required.

Pulkit_Jain_
Employee
April 26, 2022

@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-authoring/adaptive-form-expressions.html?lang=en#validations-in-adaptive-form 

 

[1] - https://experienceleague.adobe.com/docs/experience-manager-65/forms/adaptive-forms-advanced-authoring/rule-editor.html?lang=en#using-code-editor 

byhiAuthor
New Participant
April 26, 2022

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.