Skip to content

Conversation

heath-freenome
Copy link
Member

@heath-freenome heath-freenome commented Oct 4, 2025

Reasons for making this change

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 $refs 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 4 new utility functions: isFormDataAvailable(), isRootSchema(), optionalControlsId(), 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

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

@heath-freenome
Copy link
Member Author

More commits coming with the actual test and documentation updates

@heath-freenome heath-freenome changed the title Feature - Optional Data Controls Draft: Feature - Optional Data Controls Oct 4, 2025
@heath-freenome heath-freenome self-assigned this Oct 4, 2025
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
@heath-freenome heath-freenome changed the title Draft: Feature - Optional Data Controls Feature - Optional Data Controls Oct 6, 2025
-Responded to reviewer feedback

Co-authored-by: Nick Grosenbacher <[email protected]>
@heath-freenome heath-freenome merged commit 4616bb6 into rjsf-team:main Oct 8, 2025
4 checks passed
@heath-freenome heath-freenome deleted the feature-optional-data branch October 8, 2025 15:54
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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants