Skip to content

Feat/UI initial value and required#5001

Draft
adamrimon wants to merge 6 commits intorjsf-team:mainfrom
adamrimon:feat/ui-initial-value-and-required
Draft

Feat/UI initial value and required#5001
adamrimon wants to merge 6 commits intorjsf-team:mainfrom
adamrimon:feat/ui-initial-value-and-required

Conversation

@adamrimon
Copy link
Copy Markdown
Contributor

@adamrimon adamrimon commented Mar 25, 2026

Reasons for making this change

Fixes #4983

ui:emptyValue only applies when the user actively clears a field. If the user never touches it, or the form is reset, there is no equivalent. This is a gap when the JSON schema is auto-generated and a separate uiSchema layer controls the UX.

This PR:

  • Extends ui:emptyValue to apply whenever a field is blank, regardless of the reason (initial render, reset, or user clearing), by threading uiSchema through the getDefaultFormState pipeline
  • Adds ui:initialValue to pre-fill a field on render/reset, taking priority over schema.default (useful for hidden fields that need a fixed value)
  • Adds ui:required to override the schema's required status for a field. true adds the indicator and validation, false hides the indicator but does not suppress schema validation. Emits console.warn for misleading configurations

The ui:emptyValue extension is a breaking change (previously only fired on explicit clear), hence the major version bump to 7.0.0.

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

@adamrimon adamrimon force-pushed the feat/ui-initial-value-and-required branch from 2ef05b7 to 302da71 Compare March 25, 2026 13:12
… widget clear

Threaded uiSchema through the getDefaultFormState pipeline so that
ui:emptyValue is used as a fallback whenever a field is blank, regardless
of whether it became blank from initial state, reset, or user clearing.
ui:initialValue takes priority over schema.default and is used when
the form is first rendered or after a reset. It does not override
user-provided formData. emptyValue remains the fallback for blank fields.
@adamrimon adamrimon force-pushed the feat/ui-initial-value-and-required branch from 302da71 to 6445eba Compare March 25, 2026 13:14
ui:required: true adds the field to validation and shows the required
indicator. ui:required: false hides the indicator but schema validation
still runs. Emits console.warn when ui:required: false is used on a
schema-required field without ui:initialValue or ui:emptyValue.
@adamrimon adamrimon force-pushed the feat/ui-initial-value-and-required branch from 6445eba to d2bc4cf Compare March 25, 2026 13:20
@heath-freenome
Copy link
Copy Markdown
Member

@adamrimon Wow, making changes for v7 already. We have a few others queuing up for it. I hope I have some time to prepare the long-lived branch for it

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.

Extend ui:emptyValue and complement it with ui:initialValue and ui:required

2 participants