-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Feature - Optional Data Controls #4798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
heath-freenome
merged 6 commits into
rjsf-team:main
from
heath-freenome:feature-optional-data
Oct 8, 2025
Merged
Feature - Optional Data Controls #4798
heath-freenome
merged 6 commits into
rjsf-team:main
from
heath-freenome:feature-optional-data
Oct 8, 2025
Conversation
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
More commits coming with the actual test and documentation updates |
Added new `Optional Data Controls` feature as follows: - In `@rjsf/utils`: - Updated existing tests where `getDefaultFormState` is used to reflect addition of `initialDefaultsGenerated` - Updated `types.ts` to support the new `Optional Data Controls` feature as follows: - Added new `OptionalDataControlsTemplateProps` and refactored the common props from `ArrayFieldTemplateProps` and `ObjectFieldTemplateProps` into a new super type, `ContainerFieldTemplateProps` - Added new `optionalDataControl?: ReactNode` to the `ArrayFieldTitleProps`, `TitleFieldProps` and `ContainerFieldTemplateProps` - Updated `GlobalFormOptions` to add new `enableOptionalDataFieldForType?: ('object' | 'array')[]` prop - Updated `SchemaUtilsType`'s `retrieveSchema()` function to add an additional, property `resolveAnyOfOrOneOfRefs?: boolean` - Updated the `Templates` interface to add a new required template `OptionalDataControlsTemplate: ComponentType<OptionalDataControlsTemplateProps<T, S, F>>` - Updated `retrieveSchema()` to add an additional property `resolveAnyOfOrOneOfRefs?: boolean` which causes `resolveAllSchemas()` to resolve `$ref`s inside of the options of `anyOf`/`oneOf` schemas - Updated `getDefaultFormState` to fix an issue where optional array props had their default set to an empty array when they shouldn't be - Updated the `TranslatableString` enum to add three new strings in support of the new feature: `OptionalObjectAdd`, `OptionalObjectRemove` and `OptionalObjectEmptyMsg` - Added three new utility functions: `isFormDataAvailable()`, `isRootSchema()` and `shouldRenderOptionalField()` - Added or updated tests to verify all of the new behaviors - In `@rjsf/core`: - Added a new `OptionalDataControlsField` to the `fields` that renders either undefined (when there is data for a readonly/disabled field) or gets the `OptionalDataControlsTemplate` and renders the `label` and potentially an `onAddClick` or `onRemoveClick` function - Updated `ArrayField` and `ObjectField` to check whether it `shouldRenderOptionalData()` and if true, calls `ObjectDataControlsField` and passes the result to its associated render template as `optionalDataControl` - Updated `ArrayFieldTemplate`, `ObjectFieldTemplate`, `TitleField` to add support for the new `optionalDataControl` feature - Added the new `OptionalDataControlTemplate` to the theme, adding it to the `templates` list - In the rest of the themes: - Updated `ArrayFieldTemplate`, `ArrayFieldTitleTemplate`, `ObjectFieldTemplate`, `TitleField` to add support for the new `optionalDataControl` feature - Added the new `OptionalDataControlTemplate` to the theme, adding it to the `templates` list - Updated the `ButtonTemplates` classes to better support the `OptionalDataControlTemplate` - In the doc directory: - Updated `utility-function.me` docs to add documentation for the new functions - Also updated docs for `retrieveSchema` and `SchemaUtilsType` for the new prop - Updated `uiSchema.md` to add documentation for the new `enableOptionalDataFieldForType` prop - Updated the `v6x upgrade guide.md` to document the new feature and utility functions and changes to `retrieveSchema` - Updated the playground to add a new `Optional Data Controls` example - Updated the snapshot and jest tests for `Form` to test the new `Optional Data Controls` feature - Updated the `CHANGELOG.md` file accordingly
c1609c6
to
bfd48ed
Compare
nickgros
approved these changes
Oct 8, 2025
packages/core/src/components/fields/OptionalDataControlsField.tsx
Outdated
Show resolved
Hide resolved
-Responded to reviewer feedback Co-authored-by: Nick Grosenbacher <[email protected]>
x0k
added a commit
to x0k/svelte-jsonschema-form
that referenced
this pull request
Oct 20, 2025
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.
Reasons for making this change
Added new
Optional Data Controls
feature as follows:@rjsf/utils
:getDefaultFormState
is used to reflect addition ofinitialDefaultsGenerated
types.ts
to support the newOptional Data Controls
feature as follows:OptionalDataControlsTemplateProps
and refactored the common props fromArrayFieldTemplateProps
andObjectFieldTemplateProps
into a new super type,ContainerFieldTemplateProps
optionalDataControl?: ReactNode
to theArrayFieldTitleProps
,TitleFieldProps
andContainerFieldTemplateProps
GlobalFormOptions
to add newenableOptionalDataFieldForType?: ('object' | 'array')[]
propSchemaUtilsType
'sretrieveSchema()
function to add an additional, propertyresolveAnyOfOrOneOfRefs?: boolean
Templates
interface to add a new required templateOptionalDataControlsTemplate: ComponentType<OptionalDataControlsTemplateProps<T, S, F>>
retrieveSchema()
to add an additional propertyresolveAnyOfOrOneOfRefs?: boolean
which causesresolveAllSchemas()
to resolve$ref
s inside of the options ofanyOf
/oneOf
schemasgetDefaultFormState
to fix an issue where optional array props had their default set to an empty array when they shouldn't beTranslatableString
enum to add three new strings in support of the new feature:OptionalObjectAdd
,OptionalObjectRemove
andOptionalObjectEmptyMsg
isFormDataAvailable()
,isRootSchema()
,optionalControlsId()
, andshouldRenderOptionalField()
@rjsf/core
:OptionalDataControlsField
to thefields
that renders either undefined (when there is data for a readonly/disabled field) or gets theOptionalDataControlsTemplate
and renders thelabel
and potentially anonAddClick
oronRemoveClick
functionArrayField
andObjectField
to check whether itshouldRenderOptionalData()
and if true, callsObjectDataControlsField
and passes the result to its associated render template asoptionalDataControl
ArrayFieldTemplate
,ObjectFieldTemplate
,TitleField
to add support for the newoptionalDataControl
featureOptionalDataControlTemplate
to the theme, adding it to thetemplates
listArrayFieldTemplate
,ArrayFieldTitleTemplate
,ObjectFieldTemplate
,TitleField
to add support for the newoptionalDataControl
featureOptionalDataControlTemplate
to the theme, adding it to thetemplates
listButtonTemplates
classes to better support theOptionalDataControlTemplate
utility-function.me
docs to add documentation for the new functionsretrieveSchema
andSchemaUtilsType
for the new propuiSchema.md
to add documentation for the newenableOptionalDataFieldForType
propv6x upgrade guide.md
to document the new feature and utility functions and changes toretrieveSchema
Optional Data Controls
exampleForm
to test the newOptional Data Controls
featureCHANGELOG.md
file accordinglyChecklist
npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update
to update snapshots, if needed.