Repository navigation
feat(forms): conditional required fields with requiredWhen - #707
Merged
Merged
Conversation
A field can declare requiredWhen: {field, in} to be required only when a
sibling select or enum field was submitted with one of the listed values,
and optional otherwise. Activation refuses an undeclared, self-referencing,
free-text or itself-conditional sibling, an in value the sibling does not
allow, and requiredWhen together with required. Enforcement is server-only;
the input is not marked required in HTML.
Relative date bounds are split out to #705.
Fixes #528
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Fixes #528
Implements the owner's decision on #528:
requiredWhen: {field, in: [values]}on a dependent field.Behavior
in, an empty dependent field gets the same 422is requirederror as a required field (a conditional checkbox must be checked). Otherwise it is optional. Its other rules (length, pattern, enum, type, bounds) apply whenever it has a value.validateFlow) refuses: undeclared sibling; self-reference; a sibling without a fixed value set (only aselect, using itsoptions[].valuenarrowed byenumif present, or an input withenumqualify; checkboxes and free text are refused); aninvalue the sibling does not allow; a sibling that has its ownrequiredWhen(one level only); andrequiredWhentogether withrequired. The config schema refuses an empty or duplicatedin, more than 128 values (same as the enum/options limit), and unknown keys.requiredrule: fields are required by default, sorequiredWhentakes the place ofrequired.required: truecontradicts it, andrequired: falsewould only repeat it, so both are refused. That leaves one way to write it.requiredin HTML, and there is no JS or show/hide. No automatic hint is added: the author's existingdescriptionis the place to say when the field becomes required, and the README says so.onSubmit. Relative date bounds are split out to [Request]: relative date bounds for forms date and datetime-local fields #705.Changes
packages/forms/src/forms.ts: schema,validateRequiredWhen,isRequired, renderingpackages/forms/urlcode.jsonregenerated (npm run build:addons)requiredabsent, and all startup and schema refusalsdocs/page lists forms validation rules.llms-full.txtcheck is unchanged.Evidence
npm run typecheck: passnpm run verify: exit 0 (core 808/808, workspaces all pass)npm run test:package: exit 0 ("Packed installation and starter/cookbook checks passed")CI passing is not a security review.
🤖 Generated with Claude Code