react-jsonschema-form
react-jsonschema-form copied to clipboard
How to add a hidden 'comment' field to the formData?
Prerequisites
- [X] I have read the documentation
What theme are you using?
core
What is your question?
We have a use case as follows:
-
We have different product variants that use different JSON Rule Schema files to generate their Configuration Files (formData)
-
When a user loads a Configuration File in our editor from device type A, the editor should automatically load Rule Schema A
In order to achieve the above, we are currently looking for certain fields in the loaded formData - but that is not very scalable or robust. Instead, we'd prefer to add a 'variant identification field' in the formData/Schema. This field should not be displayed in the front-end (regardless of UIschema) and is purely for internal purposes - like a comment field.
Is this possible to achieve in rjsf?
Yeah I wanted to stuff a form version number in mine. I guess I'll just have to add it when saving, and remove it when loading.
I wanted a "ui:hidden":true option
I figured it out. This is my solution for hiding fields:
const schema1_0: RJSFSchema = {
title: 'Test form',
type: 'object',
properties: {
version: {
title: ' ',
type: 'string',
default: "1.0"
},
},
}
const uiSchema: UiSchema = {
"version": {
"ui:inputType": 'hidden'
}
}
It seems like you have to have a title of ' ' for it to work. Empty string will default to the field name.
Addendum: I am noticing now that some styling libraries will still display an empty box with this configuration, which is sort of ugly. It's still pretty close though.
"ui:widget": "hidden" works much better, it doesn't leave an empty box.
See: https://github.com/rjsf-team/react-jsonschema-form/pull/111
This is a duplicate of: https://github.com/rjsf-team/react-jsonschema-form/issues/43
This issue has been automatically marked as possibly close because it has not had recent activity. It will be closed if no further activity occurs. Please leave a comment if this is still an issue for you. Thank you.
This issue was closed because of lack of recent activity. Reopen if you still need assistance.