I’m looking to add a feature to my yii2 app. I already have ActiveForms working very nicely, but I have not worked with dynamically updating dropdowns via a REST API.
Currently, I have a subform based on kartik\builder\TabularForm that has three fields per row:
left-field: TabularForm::INPUT_WIDGET using widgetclass \kartik\widgets\Select2::className()
Purpose: defines “data type” being entered by User
Changes needed: none, works as is
Example data: “Product Name”, “Product Type”, “Serial#”, “Qty”, “Vendor”
center-field: TabularForm::INPUT_WIDGET using widgetclass \kartik\widgets\Select2::className()
Purpose: defines “comparison type” being entered by User
Changes needed: none, works as is
Example data: “equals”, “greater than”, “contains”, “is empty”, “is not empty”
right-field: TabularForm::INPUT_TEXTAREA
Purpose: the Search Value
Changes needed: needs update
Example data: “1”, “Large Hammer”, (null), “China”, “fish”
The field I need help with is the right-field. Based on the left-field, I may need to enter a string literal here, e.g., “glass” if the left-field is set to “Product Description”, or I may need to use a drop-down to select “Hammer” if the left-field is seto to “Product Type”.
Knowing that, I need right-field to both change its widget and dynamically grab data for widgets that allow a User to select from a set of data:
if left-field requires boolean:
TabularForm::INPUT_RADIO
if left-field requires selecting from a list, and list.count <= 50:
TabularForm::INPUT_DROPDOWN_LIST
if left-field requires selecting from a list, and list.count > 50:
kartik\widgets\Typeahead
If a List, then the data is grabbed dynamically from the app.
Note, some fields may have several thousand entries, e.g., “Product Type” may have only 20 entries but “SKU” may have 4000.