Skip to content

Let the options of a select change while the form is open - #89

Merged
KamilSztandur merged 1 commit into
mainfrom
set-options
Sep 21, 2026
Merged

KamilSztandur merged 1 commit into
mainfrom
set-options

Conversation

@KamilSztandur

Copy link
Copy Markdown
Collaborator

Problem

The list of options in a select is fixed when the field is created. There is no way to swap it later. That rules out the ordinary dependent dropdown: the instructors you can pick depend on the aircraft you chose, the cities depend on the country, the list arrives from the server after the form is already on screen. Someone porting two real forms had to give up on the built-in select for this. It is a gap, not a design choice.

Solution

setOptions(newList) on both select controllers. It replaces the list and takes care of the value:

  • A selected value that is no longer on the list is cleared (on the multi select, dropped from the set). This counts as the program's write, like prefill, not as a user edit. So a prefilled field the user never touched stays quiet until submit, while a field the user had picked from shows its "required" error right away.
  • A read-only field is cleared too, because a value that is not on the list cannot be shown in the dropdown.
  • Widgets rebuild even when the value stayed the same, so the new list appears.

Typical use is a listener on the other field:

aircraft.addListener(() {
  instructor.setOptions(instructorsFor(aircraft.fieldValue));
});

One side effect: the single select now copies the list it is given, which the multi select already did. options is read-only on both.

In this PR

  • setOptions on AdvancedSingleSelectFieldController and AdvancedMultiSelectFieldController.
  • Tests: list replaced and listeners notified with the value unchanged, off-list value cleared or dropped, no error on an untouched field, error at once on an edited one, read-only cleared, the list is a copy, disposed throws.
  • Docs: the single and multi select sections, the select rendering page, a FAQ entry with the == warning about server copies of options, SKILL.md and a changelog entry.

flutter analyze clean, all 271 tests pass.

🤖 Generated with Claude Code

Both select controllers get setOptions(List<V>). A selected value that
is not on the new list is cleared as a program write, like prefill, so
an untouched field stays quiet; widgets rebuild even when the value
stayed. The single select now copies the list it is given, as the multi
select always did.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Docs preview: https://advanced-forms-f03faufh3-leancode.vercel.app

Built from 6a6b7b9; the landing page is at /, the docs under /docs.

@KamilSztandur
KamilSztandur merged commit 63d7ced into main Sep 21, 2026
5 checks passed
@KamilSztandur
KamilSztandur deleted the set-options branch September 21, 2026 16:47
@KamilSztandur KamilSztandur mentioned this pull request Sep 21, 2026
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.

2 participants