# Dynamic Radio and Select Box Values

The Radio / Select Box component presents a set of values for end-users to select from within a form. Typically, these components are configured with static values, requiring manual adjustment of the component settings whenever new options need to be added or modified.

This documentation will illustrate the process of setting up the Select Box and Radio components to retrieve dynamic values from an external source, specifically a Form.io Resource. This functionality enables the Form Builder to effortlessly update numerous Radio or Select Box components across various forms embedded within your application by simply modifying the Data Source connected to these components

## Use Case

This example will utilize two different forms, an HR Employee form and a Job application form. The HR employee form contains a Radio component with different contact value options. Similarly, the Job application form contains a Select Box with the same type of values. Keeping the Use Case in mind, imagine that these components are not limited to just two forms but are utilized in a multitude of forms throughout your application. With this static value configuration, the form builder must manually update the values for each component incorporated into the forms.&#x20;

Manually updating these values also presents the potential for the Form Builder to make a mistake while updating the values. This could cause issues for workflows such as server-side logic or specific database configurations that rely on specific IDs or Value names from the components.  Utilizing a Dynamic Data Source alleviates these potential issues and ensures a quick update while maintaining component continuity across all of the forms.&#x20;

{% embed url="<https://www.loom.com/share/b00a30dc3c3d40938916e1c31eb644a0>" %}

## Create a Resource (Value Database)

Create a Resource to store the data values from which the Radio and Select Box components can retrieve their information.&#x20;

1. Within your Project, create a new **Resource**. \
   For this example, we will be using a Contact Method Resource to provide values for the Radio and Select Box components within the example forms.&#x20;
2. Add a **TextField** to the Resource that will support the values

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FHVDEBxGgVkHdhKIeZBpo%2FResourceContactMethod.jpg?alt=media&#x26;token=44a4a97d-58a3-42ad-9433-158f3846f30e" alt=""><figcaption></figcaption></figure>

3. Click the **Use** tab to make **submissions** against the Resource establishing the Contact Method values. These values will be changed later in the workflow. \
   E.G. Home Phone | Email | Fax&#x20;

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2F4AkCzoPWFSsS2OWeVzzF%2FContactMethodSubmission.jpg?alt=media&#x26;token=1f89836a-c3f6-49b6-ba07-e95d187f496b" alt=""><figcaption></figcaption></figure>

4. Within the **Resource**, click the more settings  tab (**...**) and select the **Form API** button
5. Copy the **Submission API** endpoint for the Resource

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FM6wGXKbpNubSwWMj5Qqz%2FContactMethodAPI.jpg?alt=media&#x26;token=682b19d9-d77e-4d18-a42f-5ef8a2a83a6b" alt=""><figcaption></figcaption></figure>

6. Click the **Access** tab for the Resource
7. Set the **Everyone** Role to the  **Read All** permission\
   This will ensure that the Resource values can be retrieved when the Form is interacted with externally.&#x20;

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FcjgIYEHFGE8bg3rFVLnk%2Fpermission.jpg?alt=media&#x26;token=cc846426-6d79-43c0-a45c-422d035824a4" alt=""><figcaption></figcaption></figure>

## Configuring Radio/Select Box Data Source

Two forms will be created that will contain the Radio and Select Box components. These will be configured to support Dynamic Values from the Resource created in the previous step.

1. Create a **form** called **Job Application**
2. Add a **Select Box** component called Contact Method&#x20;
   * Within the component settings, click the **Data** tab
   * Click the **Data Source Type** and set it to **URL**
   * Add the **Resource Submission Endpoint** to the URL field\
     `https://myproject.form.io/contactmethod/submission`
   * Modify the **Item Template** and ensure the API property name of the Contact Method field is set. It should look something like this:\
     `{{ item.data.contactMethod }}`

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FyXigpIvyB2vPKHtyoldA%2Fdatasourceurl.jpg?alt=media&#x26;token=fcc36133-da26-4c00-ae27-83b9778e33ea" alt="" width="563"><figcaption></figcaption></figure>

3. Create another **Form** called **Employee Information**
4. Add a **Radio** called **Contact Method** and follow the same workflow
   * Within the component settings, click the **Data** tab
   * Click the **Data Source Type** and set it to **URL**
   * Add the **Resource Submission Endpoint** to the URL field\
     `https://myproject.form.io/contactmethod/submission`
   * Modify the **Item Template** and ensure the API property name of the Contact Method field is set. It should look something like this:\
     `{{ item.data.contactMethod }}`
5. View the Forms within your application to

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FQoy3Dicc6IuqMfueQPgs%2FEmployeeRecord.jpg?alt=media&#x26;token=20d3f373-edaf-4705-b7d2-9f0f2619a624" alt="" width="563"><figcaption></figcaption></figure>

## Updating Resource Values

Back to the original use case, let's pretend instead of 2 forms, we have 50 forms with these components. As the Form Builder, we are tasked with removing a Value, modifying a value, and adding a value to all Contact Method fields. Instead of modifying these values manually, we can update the values directly within the Data Source, causing all connected instances of components to dynamically update.&#x20;

1. Navigate back to the **Contact Method** Resource
2. Click the **Data** tab and make the following modifications to the submissions
   * **Update** the Home Phone value to Cell Phone
   * **Delete** the Fax submission
   * **Create**  a new value called Text Message by using the Resource

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FOUO0vHk711aRvaIrImrc%2Fupdatedvalues.jpg?alt=media&#x26;token=704fc66b-04f1-4d6f-90f7-b603250a1322" alt=""><figcaption></figcaption></figure>

3. Navigate back to your application and refresh your form to pull in the changes.

Job Application Form Dynamically updates dynamically

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FLyPkaE7Ybg5trZd4IhIQ%2FJobapplicationformupdate.jpg?alt=media&#x26;token=07e2aca5-9556-488d-aeb3-c240cebcf635" alt=""><figcaption></figcaption></figure>

Employee Information Form dynamically updates dynamically&#x20;

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2F5giGcpGkr91DO1e5cmQU%2Femployeerecordformupdate.jpg?alt=media&#x26;token=5a41121f-03c2-44b5-bf5f-1d87f2c77de8" alt=""><figcaption></figcaption></figure>

## Alternative Data Sources

&#x20;Alternative API JSON endpoints can also be utilized as the Data Source. In this example, a second Select Box component is added Job Application form that will retrieve data from an API endpoint containing a JSON data object of US States.

1. Add a **Select Box** component called Contact Method&#x20;

   * Within the component settings, click the **Data** tab
   * Click the **Data Source Type** and set it to **URL**
   * Add the **API  Endpoint** containing the JSON object of US States to the URL field. Copy the link location of [states.json](https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FwmAq91bwK86ah0TVWHFb%2Fstates.json?alt=media\&token=bcf83383-f5e4-48b4-b977-4a0ad22b044e) and paste it into the field.&#x20;
   * Modify the **Item Template** and ensure the name property of the JSON object is included\
     `{{ item.name }}`

   <figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FakAPVcIVJTn8am2UmGNl%2Fstateurlconfig.jpg?alt=media&#x26;token=2f769894-bcce-4d7b-a75b-aa6d356c066d" alt="" width="398"><figcaption></figcaption></figure>

   * Alternatively, you can set the Item Template to pull in the State abbreviation by configuring the Item Template to include the abbreviation property of the State instead of the name \
     `{{ item.abbreviation }}`
2. &#x20;Navigate back to your application and refresh your form to pull in the changes.

<figure><img src="https://3305536326-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MPHoF2HwOA0s5HV_AIB%2Fuploads%2FuWpjEmHsH9X8H1AfJloa%2Fjobappstateapi.jpg?alt=media&#x26;token=31116b76-7ba9-4a06-af26-b7a1336ad687" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.form.io/faq/tutorials-and-workflows/dynamic-radio-and-select-box-values.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
