#dynamic Json form inputs

1 messages Β· Page 1 of 1 (latest)

lean hedge
#

Is there a way to have a form auto generate its input fields based on a SQL query?

As an example, I have a table with failure modes for an assembly station.
The table has: Id, 'Failure_Mode_Name', and 'Related_Station_Id'.
I want to be able to have a selector in a form to pick a 'related_station_Id' and have inputs for each of the related Failure_Mode_Names.

So, If I select Station Id 2, I want to see all the failure mode names related to that station.
Here's an example table.
In this example I should see Ids 2, 3, 5, 6

β•‘ Id β•‘ Failure_Mode_Name β•‘ Related_Station_Id β•‘
╠════╬═══════════════════╬════════════════════╣
β•‘ 1  β•‘ Open              β•‘ 1                  β•‘
╠════╬═══════════════════╬════════════════════╣
β•‘ 2  β•‘ Missing Coil      β•‘ 2                  β•‘
╠════╬═══════════════════╬════════════════════╣
β•‘ 3  β•‘ test              β•‘ 2                  β•‘
╠════╬═══════════════════╬════════════════════╣
β•‘ 4  β•‘ Open              β•‘ 6                  β•‘
╠════╬═══════════════════╬════════════════════╣
β•‘ 5  β•‘ Column Shorts     β•‘ 2                  β•‘
╠════╬═══════════════════╬════════════════════╣
β•‘ 6  β•‘ HC Shorts         β•‘ 2                  β•‘
β•šβ•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•©β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•```
sand lavaBOT
#

Hello! I'm AppsmithBot, here to assist you with your Appsmith queries.

To achieve the functionality you described, you can follow these steps:

  1. Create a SQL Query: First, create a SQL query to fetch the failure modes based on the selected Related_Station_Id. For example:

SELECT Id, Failure_Mode_Name FROM your_table_name WHERE Related_Station_Id = {?{ StationSelector.selectedOptionValue }?}

Replace your_table_name with the actual name of your table and StationSelector with the name of your dropdown widget.

  1. Add a Dropdown Widget: Add a dropdown widget to your form to select the Related_Station_Id. Populate this dropdown with unique station IDs from your table.

  2. Bind the Query to the Dropdown: Set the onOptionChange property of the dropdown to run the SQL query you created. This will fetch the relevant failure modes whenever a station ID is selected.

  3. Display the Results: Use a List widget or a Container widget to dynamically display the input fields for each Failure_Mode_Name. You can bind the data from the SQL query to these widgets.

For example, if using a List widget, set the Items property to the query result:

{?{ SQLQueryName.data }?}

Inside the List widget, you can add input fields and bind their default values to the Failure_Mode_Name:

{?{ currentItem.Failure_Mode_Name }?}

By following these steps, you can dynamically generate input fields based on the selected Related_Station_Id. Let me know if you need further assistance!

If you don't find my response helpful, you can request to speak to a human agent.