Action: Autofill

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:

  1. Set up a data provider using the get-countries JSON web service. If you’re running Liferay DXP at localhost:8080, you can access this web service here:

    http://localhost:8080/api/jsonws?contextName=&signature=%2Fcountry%2Fget-countries-0
    

    Make sure the output parameter is set to $..nameCurentValue. If you’re unsure how to do this, first read the article on Data Providers.

  2. 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.

Using Inputs with 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),

  1. Create a Data Provider.

    Name: restcountries

    URL: https://restcountries.eu/rest/v2/region/{region}?fields=name

    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.

    Figure 3: Create a data provider for the autofill rule.

    Figure 3: Create a data provider for the autofill rule.

  2. Create a form with these fields:

    Text: Use the Label Region.

    Select from List: Label it Country, and choose From Autofill under Create List.

    Figure 4: Create a form with a text field and a select from list field. These are used to provide the input to the data provider and be autofilled by its output.

    Figure 4: Create a form with a text field and a select from list field. These are used to provide the input to the data provider and be autofilled by its output.

  3. 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.

    Figure 5: Create the autofill rule. Brag of your prowess.

    Figure 5: Create the autofill rule. Brag of your prowess.

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.

Figure 6: Filter countries by region of the world.

Figure 6: Filter countries by region of the world.

Autofill rules combine the power of data providers and form rules.

« Action: Jump to PageAction: Calculate »
Was this article helpful?
1 out of 1 found this helpful