Explain how a prefilled field can react to another field before the user touches it - #90
Merged
Merged
Conversation
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>
KamilSztandur
requested review from
PiotrRogulski and
mateusz-pietras
as code owners
September 20, 2026 19:46
|
Docs preview: https://advanced-forms-pjxkmu9x6-leancode.vercel.app Built from 2eb4f01; the landing page is at |
mateusz-pietras
approved these changes
Sep 21, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
subscribeToFieldsdoes 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.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, andvalidate()also runs the async validator, so a field with a server check will call the server on every change.In this PR
The snippet was run against the package before writing it up.
🤖 Generated with Claude Code