rjsf-team/react-jsonschema-form

Add defaultFormStateBehavior initialRender type "populateRequiredDefaults"

Open

#4604 opened on May 6, 2025

View on GitHub
 (4 comments) (0 reactions) (0 assignees)TypeScript (13,175 stars) (2,136 forks)batch import
featurehelp wanted

Description

Prerequisites

What theme are you using?

mui

Is your feature request related to a problem? Please describe.

Integrating with Pydantic on the backend, I have many default variables set to allow my users quick form generation and form submission. My users also don't like the fact that they cannot delete the entire input box to put in there own value (it prevents them from doing this due to the nature of how defaults are populated).

I can manipulate this behavior by setting:

experimental_defaultFormStateBehavior={{
   emptyObjectFields: 'skipEmptyDefaults'
}}

To ease this.

However, on the frontend, there is no feature to allow for "initial default generation", such that when the prop formData is past in as {}, the defaults can populated for the form initially.

Describe the solution you'd like

With a feature flag such as:

experimental_defaultFormStateBehavior={{
   initialRender: 'populateRequiredDefaults'
}}

The form would be prepopulated (even with a blank object such as {}). In combination with emptyObjectFields: 'skipEmptyDefaults', a user could have the defaults shown to them, while also being able to delete it if they want too.

Describe alternatives you've considered

No response

Contributor guide