Skip to content

Feat/custom template per field #4352

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

lucasmcht
Copy link

Fixes #3695 (Rework of PR #3881)

Reasons for making this change

Currently, to per-field customize the template, it is necessary to send the function/class of the component in the uiSchema, breaking the JSON nature of the uiSchema. It's not possible to provide just the registration key.

This pull request includes updates to the @rjsf/utils package to allow for per-field customization using string keys from the Registry, as well as updates to the documentation to reflect these changes. Additionally, it simplifies the types in the codebase by introducing a new RJSFBaseProps type.

Feature Enhancements

  • packages/utils/src/getTemplate.ts: Updated getTemplate() to allow per-field customization using string keys from the Registry.

Documentation Updates

  • packages/docs/docs/advanced-customization/custom-templates.md: Updated to include examples of specifying templates using both components and string values from the Registry.

Type Simplification

  • packages/utils/src/types.ts: Introduced RJSFBaseProps to simplify and consolidate the properties passed to various template components. This change affects multiple type definitions, including ErrorListProps, FieldErrorProps, FieldHelpProps, FieldTemplateProps, and others.

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

/** The `registry` object */
registry: Registry<T, S, F>;
};

/** The set of RJSF templates that can be overridden by themes or users */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding documentation around the change you made below, here as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what kind of documentation I should add, could you specify please ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest mentioning the ability to add per-field customizations and maybe add an example of a custom template since it is now supported?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, I'm super glad this feature is finally getting into the master branch. It's almost having an one year birthday 🎂. We use this feature extensively to customize the layout of the form. I think its a very nice use case to describe in the docs, since I'm aware it's a very long desired flexibility. I could also contribute by providing the Layout template.

@heath-freenome
Copy link
Member

@lucasmcht Also, can you fix the type errors in the themes?

@heath-freenome
Copy link
Member

@lucasmcht Some of your tests are failing

@heath-freenome
Copy link
Member

@lucasmcht Please fix the tests so that we can merge this. Thanks

@heath-freenome
Copy link
Member

@lucasmcht are you able to do the final bits so that we can merge your work?

@lucasmcht
Copy link
Author

@heath-freenome Yes I just need to find some bandwith and I'll finish the feature, I'll finish it this week or the next

@heath-freenome
Copy link
Member

@heath-freenome Yes I just need to find some bandwith and I'll finish the feature, I'll finish it this week or the next

@lucasmcht still waiting for you to finish this... Note that soon we will be merging in our rjsf-v6 branch to main and starting a beta, so the sooner you complete this the better

@lucasmcht
Copy link
Author

@heath-freenome Should be fixed now. Sorry for the delay.

@heath-freenome
Copy link
Member

@lucasmcht Looks like you are using something more modern than our babel supports. The pipeline is failing

@lucasmcht
Copy link
Author

@heath-freenome Is it better now ?

@heath-freenome
Copy link
Member

heath-freenome commented Mar 27, 2025

@lucasmcht was it really Node 14?! We are dropping support for it in the rjsf-v6 beta. Maybe it makes sense to put your fix into the rjsf-v6 branch instead and restore the code you switched in your last commit. If so, you can just update the CHANGELOG_v6.md instead of CHANGELOG.md. If not, can you at least add a comment to restore the hasOwn() functions in v6

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.

current per-field customization break JSON rules
3 participants