Está viendo la ayuda para la versión:
This tutorial is a step in the Create Your First Adaptive Form series. Adobe recommends following the series in chronological sequence to understand, perform, and demonstrate the complete tutorial use case. |
You can use rules to add interactivity, business logic, and smart validations to an adaptive form. Adaptive forms have a built-in rule editor. The rule editor provides a drag-and-drop functionality, similar to guided tours. The drag-and-drop method is the fastest and easiest method to create rules. The rule editor also provides a code window for users interested in testing their coding skills or taking the rules to the next level.
You can learn more about the rule editor at Adaptive Forms rule editor.
By the end of the tutorial, you will learn to create rules to:
- Invoke a Form Data Model service to retrieve data from the database
- Invoke a Form Data Model service to add data to the database
- Run a validations check and display error messages
Interactive GIF images at the end of each section of the tutorial help you learn and validate the functionality of the form you are building, on the fly.
You created a form data model by following the create form data model article. Now, you can use the rule editor to invoke the Forms Data Model services to retrieve and add information to the database.
Every customer is assigned a unique Customer ID number, which helps identify relevant customer data in a database. The procedure below uses the Customer ID to retrieve information from the database:
-
Open the adaptive form for editing.
http://localhost:4502/editor.html/content/forms/af/change-billing-shipping-address.html
After the customer details are retrieved from the database, you can update the shipping address, state, and zip code. The procedure below invokes a Form Data Model service to update customer information to the database:
-
Drag-and-drop the Shipping Address, State, and Zip Code field from the Form Objects tab to the corresponding
tablename .property (for example,customerdetails .shippingAddress) of the Drop object or select here field in the INPUT box. All the fields prefixed withtablename (For example,customerdetails in this use case) serve as input data for the update service. All the content provided in these fields is updated in the data source.Nota:
Do not drag-and-drop the Name and Customer ID fields to the corresponding tablename.property (for example, customerdetails.name). It helps avoid updating name and ID of the customer by mistake.
-
Drag-and-drop the Customer ID field from the Form Objects tab to the id field in the INPUT box. Fields without a prefixed
tablename (for example,customerdetails in this use case) serve as a search parameter for the update service. The id field in this use case uniquely identifies a record in thecustomerdetails table.
You should run validation on the form to ensure that the data entered in the form is correct and an error message is displayed in case of incorrect data. For example, if a non-existing Customer ID is entered in the form, an error message should be displayed.
Adaptive forms provide several components with built-in validations, for example, email, and numeric fields that you can use for common use cases. Use the rule editor for advanced use cases, for example, to display an error message when the database returns zero (0) records (no records).
The following procedure shows how to create a rule to displays an error message if the Customer ID entered in the form does not exist in the database. The rule also brings the focus to and resets the Customer ID field. The rule uses the dataIntegrationUtils API of the form data model service to check if the Customer ID exists in the database.
-
Replace the guidelib.dataIntegrationUtils.executeOperation (operationInfo, inputs, outputs) section with the following code:
guidelib.dataIntegrationUtils.executeOperation(operationInfo, inputs, outputs, function (result) { if (result) { result = JSON.parse(result); customer_Name.value = result.name; customer_Shipping_Address = result.shippingAddress; } else { if(window.confirm("Invalid Customer ID. Provide a valid customer ID")) { customer_Name.value = " "; guideBridge.setFocus(customer_ID); } } });