Search code examples
formio

formio: How to populate fields without custom javascript code?


I have searched for hours and tried several approaches. No luck.

Scenario:

There is a formio Resource Form for Doctors that includes the Doc's practice number, name, address, etc.

A new form is created for prescription medication. The form has a Select component to find the doctor's practice number. Once the correct doctor is selected, the fields showing the Doc's name, surname, address, etc., must be automatically populated.

I understand that anything is possible with custom code, but this is such a common requirement that I'm convinced it can be done with standard functionality.

Can you show me how to do this?

Thanks, Alan


Solution

  • In the validation tab, do a custom validation.

    Using the drop down's value, look up the doctor's information.

    Then, use the following code as a guide to update your fields.

    FormioUtils.searchComponents(form.components, {key:"address"})[0].setValue("PO Box 123");