Skip to content

Explain how a prefilled field can react to another field before the user touches it - #90

Merged
KamilSztandur merged 1 commit into
mainfrom
untouched-field-workaround
Sep 21, 2026
Merged

KamilSztandur merged 1 commit into
mainfrom
untouched-field-workaround

Conversation

@KamilSztandur

Copy link
Copy Markdown
Collaborator

Problem

A field the user has never edited never validates on its own. That is deliberate: a form filled from the server should not open covered in errors. The side effect is that subscribeToFields does nothing for such a field. Example: the instructor is prefilled from the server, the user switches the aircraft, and the instructor is no longer rated for it. Nothing happens, because nobody touched the instructor field.

Someone porting two real forms took this for a missing feature and ended up writing the error by hand with setError, next to a validator that already knew the rule. We are keeping the rule. What was missing is the documented way to get around it in the cases that need it.

Solution

Docs only, no code change. Call validate() on the dependent field from a listener on the watched field. validate() ignores both the mode and the "never edited" gate, so it reaches a prefilled field, and the sync result appears at once. The rule stays in the validator; the listener only decides when it runs.

var lastAircraft = aircraft.fieldValue;
aircraft.addListener(() {
  if (aircraft.fieldValue == lastAircraft) return;
  lastAircraft = aircraft.fieldValue;
  instructor.validate();
});

The write-up names the two traps I hit while checking this: a validate() that is already running is shared, so a second call in the same tick gets the first round's result, and validate() also runs the async validator, so a field with a server check will call the server on every change.

In this PR

  • SKILL.md: a new bullet in the cross-field section, with the snippet and the traps.
  • FAQ: a paragraph in "My subscribeToFields dependency does not re-validate".
  • Cross-field docs: one sentence in "What it does, precisely".

The snippet was run against the package before writing it up.

🤖 Generated with Claude Code

subscribeToFields never reaches a field the user has not edited; that
is the model and stays. Document the way to do it when a prefilled field
must react anyway: validate() from a listener on the watched field, with
its two traps.

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

Copy link
Copy Markdown

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

Built from 2eb4f01; the landing page is at /, the docs under /docs.

@KamilSztandur
KamilSztandur merged commit eb36ecb into main Sep 21, 2026
5 checks passed
@KamilSztandur
KamilSztandur deleted the untouched-field-workaround branch September 21, 2026 16:46
@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