Hi Kanwaljit,
These are the answers to the three questions which you have asked,
a) Ajax Submit of adaptive form can be achieved using guideBridge#submit API. This API take an options object which consists of four members, (success, error, validate and context) as seen below.
/** * <p>Submits the adaptive form to the pre-configured submit action. It can also validate the adaptive form * before submission.</p> * * @param options {object} The signature of the object is * <pre><code> * { * validate: true, * success: function(guideResultObject) {}, * error: function(guideResultObject) {}, * context: obj * } * <table> * <tbody> * <tr> * <td>validate (optional)</td> * <td>object</td> * <td>If true validations are run, otherwise not</td> * </tr> * <tr> * <td>success (optional)</td> * <td>function</td> * <td>function called in case of success. An object of type {@link GuideResultObject} will be passed * as argument.<p><i><b>Note</b>: If provided, submit would be ajax submit.</i></p></td> * </tr> * <tr> * <td>error (optional)</td> * <td>function</td> * <td>function called in case of error. An object of type {@link GuideResultObject} will be passed * as argument</td> * </tr> * <tr> * <td>context (optional)</td> * <td>object</td> * <td>context will be used as <i>this</i> in the success/error handlers</td> * </tr> * </tbody> * </table> * @method * @memberof GuideBridge * @instance */ guideBridge.submit = function (options) {};If there a success option passed, then the submit is an ajax submit.
b) To validate an adaptive form, you can make use of the guideBridge#validate API [1]
c) For passing messages to the client based on custom validations done on the server, you need to forward the request back with the required data. If you need to leverage the client side validation on the server, you can enable the server side validation option from Adaptive Form Container Dialog. If your validations are custom, then you can do something like this in your custom Submit action which you had created,
// Note: the CustomparameterRequest and GuideConstants are part of com.adobe.forms.common.submitutils // and com.adobe.aemds.guide.utils package // create a new sling http servlet request SlingHttpServletRequest wrappedErrorRequest = new CustomParameterRequest(request, wrappedParameterMap, "GET"); // set your custom error message as an attribute in request // so that you can use this in your page template to show it in client wrappedErrorRequest.setAttribute("error_list", <custom_error_list>); // Set the data attribute to restore the state of the adaptive form in this new request wrappedErrorRequest.setAttribute("data", request.getParameter("jcr:data")); // Create the dispatcher options with no suffix and selector RequestDispatcherOptions options = new RequestDispatcherOptions(); options.setReplaceSuffix(null); options.setReplaceSelectors(null); // Forward the request to the page request.getRequestDispatcher(request.getParameter(GuideConstants.SELF_URL) + ".html", options).forward(wrappedErrorRequest, response); // Now in your page template, check if error_list present and use it <c:if test="<%= request.getAttribute('error_list') != null%>"> // render the message in HTML </c:if>
[1] https://helpx.adobe.com/aem-forms/6/javascript-api/GuideBridge.html