react-jsonschema-form icon indicating copy to clipboard operation
react-jsonschema-form copied to clipboard

How to add a hidden 'comment' field to the formData?

Open MatinF opened this issue 2 years ago • 4 comments

Prerequisites

What theme are you using?

core

What is your question?

We have a use case as follows:

  1. We have different product variants that use different JSON Rule Schema files to generate their Configuration Files (formData)

  2. 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?

MatinF avatar Jan 10 '23 12:01 MatinF

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

adjenks avatar May 19 '23 21:05 adjenks

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.

adjenks avatar May 19 '23 21:05 adjenks

"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

adjenks avatar May 23 '23 22:05 adjenks

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.

stale[bot] avatar Aug 22 '24 01:08 stale[bot]

This issue was closed because of lack of recent activity. Reopen if you still need assistance.

stale[bot] avatar Sep 21 '24 09:09 stale[bot]