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

Conditionally set user input in one form field as value for another form field

Open krutarthdarji opened this issue 2 years ago • 3 comments

Prerequisites

What theme are you using?

antd

What is your question?

Suppose there are three properties in the schema. 1. First name 2. select menu with 2 option (1. Self 2. other) 3. Generated First name.

For example user wrote "abc" in First name form field and then selected Self in the select menu. On selecting self value of the Generated First name should be set as "abc". If user selected other in select menu than user should manually type for generated first name.

Please help in building the schema for the same if it is possible.

krutarthdarji avatar Mar 25 '23 05:03 krutarthdarji

We should not use react in this case, for example we can implement above requirement using onChange function in some way like this but this can't be used for implementation > if (e.target.value) === 'Self' { setFormData({...formData, generatedFirstName: firstName}) }

Requirement is to get dynamic schema.

krutarthdarji avatar Mar 25 '23 05:03 krutarthdarji

Try using a if-then-else or a dependency? https://json-schema.org/understanding-json-schema/reference/conditionals.html. Although note that RJSF is still using the older dependency keyword in the JSON Schema 7 spec and not the newer ones

heath-freenome avatar Mar 30 '23 15:03 heath-freenome

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 Jun 29 '24 18:06 stale[bot]

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

stale[bot] avatar Jul 29 '24 23:07 stale[bot]