-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
conditional show/hide of group fields #315
Comments
I would also like to know if this is possible. |
implemented dynamic schemas with #322 |
This should be possible with schema dependencies like this: {
"type": "object",
"properties": {
"name": { "type": "string" },
"credit_card": { "type": "number" }
},
"required": ["name"],
"dependencies": {
"credit_card": {
"properties": {
"billing_address": { "type": "string" }
},
"required": ["billing_address"]
}
}
} Apparently this is not fully supported: Object is missing the required property 'billing_address' |
What is the status of this? Would this also support toggling fields based on the value of a select element? |
+1 |
+3 |
+3K |
+3M |
Another possibility would be that strings corresponding to boolean expression are supported for the
|
Do it using oneOf
Try it here |
One question about this. The above solution forces the driver of the dependency (Payment Method) to be a dropdown selection. It doesn't appear that any other format is supported (i.e. checkbox, per the original ask). In other words, I would like to be able to ask for a first condition in boolean format (i.e. 'Show form') and depending on whether that box is checked, then you would either get one of the forms or nothing.
Per the example above, I would want to have that first 'Show form' condition determine whether or not the rest of the form appears. Obviously, this isn't set up as a boolean so I can't just set the format to checkbox but are there alternatives to getting a boolean to determine whether another item shows up or not? |
The original request was to have values appear and disappear in the UI and the produced JSON value based on user interaction and the value of a property. It was suggested this could be done using schema dependencies, but that doesn't work. A behavior similar to the original request can be achieved using oneOf, possibly in addition to the other suggestions above If you set the first entry in your oneOf array to be a schema with "type": "null", it results in a UI that I find workable. There's still a problem with excessive white space, that the author should fix. The problem is the container for the Collapse, Edit Json, and Properties controls isn't removed/hidden when those are all disabled. See it here
|
Right, apologies if I wasn't clear but my specific question is around that first layer and specifically using a boolean to determine if a dependent option is visible. The primary reason for wanting this to be a boolean, is such that I can use the checkbox format. I basically want to have a first checkbox (not a drop down) where I set a value to true or false. If set to true, I get an additional form with a set of options. If set to false, I get nothing. The example you provided is in line with my original post where you get have to use a drop down since oneOf doesn't work like a boolean. Thanks! |
I don't think there's a way to achieve what you want. Using oneOf is the only thing currently available. In a way, it seems more complicated to use 2 controls (a check-box and a drop-down) to get the same end results with just a drop down that has "None" (or equivalent) as the first choice of many. Having said that, if there's only one choice other than "None", a checkbox is better. If you think about it, what you're asking for is a simpler interface for non-required (aka optional) properties. Currently their presence is controlled using a checkbox in the Properties drop-down. It would be simpler if the checkbox were shown with the label for the property. The label for optional fields would always be shown, but the UI elements for the property would only be shown if the checkbox is checked. This is still not exactly what was requested in the original request as the behavior is not controlled by the value of another property. Instead it is controlled by whether or not the property is required. |
This example is very good. But how I can "Payment Method" check in output JSON? Only details is present. |
The schema must be defined in such a way that a valid value will validate against exactly one of the oneOf schemas (that's what oneOf means). A simple approach is to check for the presence of unique properties to determine which one is used. For example, when property 'bankName' is present you know it must be a "Bank EFT", and when property 'cardType' is present, you know it must be a "Credit Card" |
I thought so. Is it possible add anyOf-key to output JSON? (field with predefined value). Thanks! |
Add a required hidden property to each oneOf schema, with the same name but different single valid value. Try it here |
I'm facing a similar issue. I am trying to use OneOf but the dropdown is not rendering correctly. Can anyone offer some feedback? Here's the snippet: The gist of what I'm trying to do is similar to what @gfb107 mentioned. I'm trying to display properties based on what the user selects from this said dropdown i.e. show extra fields if they need them or hide them accordingly. Pardon the formatting. |
Is it possible to define in a scheme that the editor should show or hide specific fields depending on values of others?
Like for example if I have a choice checkbox field "use credit card" and only when it is checked then an additional group of fields should be show for all credit card details ...
Save is also valid for the validation - when the group is hidden - now validation on it should be done.
That will be definitely an awesome feature!
The text was updated successfully, but these errors were encountered: