DropdownAddOption()
Adds an option to a dropdown select element. Call this before initializing the dropdown with Init().
Syntax
Result = MaterialSB::DropdownAddOption(Text.s, Value.s, SelectElement, Selected = #False)
Parameters
| Text.s | The display text shown in the dropdown. |
| Value.s | The value associated with this option (returned by GetValue()). |
| SelectElement | The dropdown element returned by Dropdown(). |
| Selected | Optional. #True to make this option initially selected. Default is #False. |
Return Value
Returns the option element.
Remarks
Add all options before calling Init() on the dropdown. The first option is typically a placeholder like "Select..." with an empty value.
Example
Global categoryDropdown
Procedure OnCategoryChange()
Protected value.s
!v_value = v_categorydropdown.value;
If value <> ""
MaterialSB::Toast("Selected category: " + value)
EndIf
EndProcedure
Procedure Main(Success)
If Success
MaterialSB::Row(MaterialSB::#Grid_Container)
MaterialSB::Col(12, 6, 4)
MaterialSB::Card()
MaterialSB::CardContent()
MaterialSB::Append(MaterialSB::Header("Product Filter", 4))
; Create dropdown
categoryDropdown = MaterialSB::Dropdown("Category")
; Add options
MaterialSB::DropdownAddOption("All Categories", "", categoryDropdown, #True)
MaterialSB::DropdownAddOption("Electronics", "electronics", categoryDropdown)
MaterialSB::DropdownAddOption("Clothing", "clothing", categoryDropdown)
MaterialSB::DropdownAddOption("Books", "books", categoryDropdown)
MaterialSB::DropdownAddOption("Home & Garden", "home", categoryDropdown)
MaterialSB::DropdownAddOption("Sports", "sports", categoryDropdown)
; Initialize after adding all options
MaterialSB::Init(categoryDropdown, #Null)
; Add change callback
MaterialSB::InputSetCallback(categoryDropdown, @OnCategoryChange())
MaterialSB::CloseCurrentParent()
MaterialSB::CloseCurrentParent()
MaterialSB::CloseCurrentParent()
MaterialSB::CloseCurrentParent()
EndIf
EndProcedure
MaterialSB::Download(@Main())