Skip to content

add api functions of select - #17

Merged
ulsyemr merged 1 commit into
MehmetCelik4:mainfrom
ulsyemr:feat/programmatic-value-api
Aug 17, 2026
Merged

add api functions of select#17
ulsyemr merged 1 commit into
MehmetCelik4:mainfrom
ulsyemr:feat/programmatic-value-api

Conversation

@ulsyemr

@ulsyemr ulsyemr commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Why

Host apps need to drive a select from their own code — restoring a value after a Turbo Stream update, or reading the current selection from another controller. Today that means reaching into the markup and rebuilding internal state by hand, which every host ends up reimplementing slightly differently.

What

const select = application.getControllerForElementAndIdentifier(element, "advanced-select")

select.getValue()                        // => "7", or ["3", "7"] on a multiple select
select.setValue("7")
select.setValue(["3", "7"])
select.setValue("7", { silent: true })   // assign without broadcasting a change
select.refresh()                         // re-render from the current selection

getValue returns the submit value: a string for single selects, an array for multiple selects, empty when nothing is selected.

setValue matches each value against the options in the list by either the option's id or its submit value, so setValue("identity-7") and setValue("submit-7") select the same row. Decisions worth naming, all covered by tests:

  • a value matching no option is still assigned and submitted, using the value itself as its label, so a server-assigned value is never silently dropped
  • "", null and [] clear the field
  • on a single select only the first value of an array is kept

silent: true suppresses change and advanced-select:change for that one assignment — for restoring a value rather than choosing one, so dependent fields do not cascade off a change the user did not make. It lasts a single render; the next assignment broadcasts normally.

@ulsyemr
ulsyemr merged commit 0f64865 into MehmetCelik4:main Aug 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant