Autofill rules let you change the selection options of another field based on the value entered into a related field. A data provider’s output is used to populate a field, as long as the condition is met.
Before configuring an autofill rule, set up a data provider. That’s how autofilled fields are populated. Pay careful attention to the input and output parameters you choose when setting up the rule.
To follow this example:
Set up a data provider using the
get-countriesJSON web service. If you’re running Liferay DXP at
localhost:8080, you can access this web service here:
Make sure the output parameter is set to
$..nameCurentValue. If you’re unsure how to do this, first read the article on Data Providers.
On the last form page, add two fields:
A Single Selection field called If I win I’d like my award to be:, with two choices: Cash and All Expenses Paid Vacation.
A Select from List field called Choose a Destination Country. Under Create List, choose From Autofill.
The above example is simple, using only an Output to autofill a Select from List field if another field has a certain value. Many times, the response from the REST provider must be filtered before display in the Select from List field. For this, a Data Provider Input field is required. For example, to configure an autofill rule to display the countries of the world filtered by a Region field (for example, Americas, Europe, or Oceania),
Create a Data Provider.
Inputs: Fill in the Label (region), Parameter (region), and Type (Text).
Outputs: fill out a Label (name), Path ($..name), and Type (List).
To understand more about these values, read the Data Provider documentation.
Create a form with these fields:
Text: Use the Label Region.
Select from List: Label it Country, and choose From Autofill under Create List.
Configure the Autofill rule.
Condition: If Region Is not Empty
Action: Do Autofill From Data Provider
restcountries, Data Provider’s Input: region—Region, Data Provider’s Output: name—Country.
Once you’re done, publish the form and try it out, by entering a valid region into the Region field, and observing that the options in the Select from List Field are filtered based on the Region. The restcountries.eu service has these regions you can use: Africa, Americas, Asia, Europe, Oceania, and Polar.
Autofill rules combine the power of data providers and form rules.