-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
feat: add custom component by id #3740
Conversation
Hi @lironhl this is a great idea! Can you fix the lint errors and add a test to SchemaField.test.jsx to verify that a custom field that matches an ID is used? |
I agree! Also please update the |
Thanks! I really appreciate the encouragement guys! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also if you want to rephrase my English you're more than welcome :) |
packages/docs/docs/advanced-customization/custom-widgets-fields.md
Outdated
Show resolved
Hide resolved
@lironhl I made a few small changes on the typos and docs but this looks great to me! I'll merge as soon as the build passes. |
@@ -134,6 +134,41 @@ describe('SchemaField', () => { | |||
}); | |||
}); | |||
|
|||
describe('Custom type component', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By the way, thanks for adding this missing test!
Reasons for making this change
Hi!
I added a feature that let's you render a custom field component for a schema, according to a schema
$id
I added this feature because in my use case I had two string fields that needed to be rendered in different ways -
Let me demonstrate, suppose I have this
json-schema
:Let's treat this
json-schema
asjson-schema
that represents a customer order in my restaurant website.I'd want
react-jsonschema-form
to render the first propertycustomerName
as regular field of string input.But to maximize the customer UX I'd want
react-jsonschema-form
to be able to let me render the fieldsfirstDish
andsecondDish
with custom components that also auto-complete the user input with dishes name from the restaurant.In the current way of using
react-jsonschema-form
I suppose I could achieve this behaviour by iterating over myjson-schema
and buildinguiSchema
according to my wishes.But I find iterating over
json-schema
hard because ofref
keyword and it's general nested structure.I thought that because of the reason that
react-jsonschema-form
has option to render custom field according toschema type
, a good and valuable addition would be to render custom field according toschema $id
.So now instead of the
json-schema
above, you could enter thisjson-schema
:And add this prop to the
Form
component:And then have the
customerName
field render as planned andfirstDish
andsecondDish
render differently as planned.I'd love to hear feedback and change my code if needed :)
Screencast.from.24-06-23.16.13.45.webm
How do I added it to the Agenda? I'll leave a message about this PR on the discord community
Checklist
npm run test:update
to update snapshots, if needed.