-
Notifications
You must be signed in to change notification settings - Fork 380
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
Option to clear value of form control when it gets disabled #2412
Comments
Hi @AtjonTV, Conceptually we don't do any automatic data manipulation in JSON Forms based on UI rendering. When introducing features like this, it's easy to get weird edge cases. For example if you use categories, then the nested enable/hide rules would only be executed for the currently active category. So only disabled fields of that category are cleared, but not of all the others. The cleanest solution is to use a middleware and in there delete properties once you no longer need them. The challenge here is to design this in a way so you don't repeat yourself between the UI Schema and your middleware functionality. A UI-based solution (with all of the mentioned downsides), could be to implement a CATCH-ALL renderer for properties. That one would just check the Forking is of course always possible. The rules are for example evaluated here. However there you can't do (or rather should not do) any data manipulation. So instead you would add this to the Vue-Vuetify bindings, for example here you could check the Generally you need some kind of backend/database protection/validation though. You can't rely on the UI to protect your database as this is easily circumvented. |
@sdirix thank you for that information. Currently, I verify the data against the data json-schema on the server, before allowing it to enter the database. But from what I can see, I can't define rules like "if a is not b, then c must be empty" in the data schema. Not sure what the best solution here is, without writing very data-schema specific code, which I want to avoid. |
Is your feature request related to a problem? Please describe.
I am building an application in Vue that has a huge form with optional fields. I control the availability of the fields with enable rules in the UI schema and required conditions in the data schema.
Here is a typical example of an UI element:
And here is the required condition from the data schema:
What I need is the ability to have fields like "mutationOfGeneticDiabetes" be cleared, when its toggle field "typeOfGeneticDiabetes" is set to a falsy condition (in this case the "typeOfGeneticDiabetes" is set to "MODY").
Describe the solution you'd like
Add an "clearValueOnDisable" toggle to form controls (in its "options" object) to have their value cleared when they get disabled. Then the toggle could be selectively applied to the fields in UI schema where it is needed.
Describe alternatives you've considered
The only options to consider where:
Package
Vue Vuetify Renderers, Vue Bindings, Core
Additional context
No response
The text was updated successfully, but these errors were encountered: