RXNT/react-jsonschema-form-conditionals

Conditions within array items

deepan-itela opened this issue · 4 comments

I have a schema with an array, each array item has 2 text fields and one checkbox. Once the checkbox is checked another text field should appear within the same array item. How can I write a rule for this scenario?

This seems to be not a trivial case, because you would have a different schema for different element in the array (https://cswr.github.io/JsonSchema/spec/arrays/) and you would need to change them independently.

I would try to make a custom field for this array, that would render additional input on checkbox change (https://github.com/mozilla-services/react-jsonschema-form#custom-field-components), this should be easier, depending on the size of the array.

But it will be great if there is a generic syntax like this:

{ "conditions": { "propertyOwn[this].isInvestmentProperty": { "is": true } }, "event": { "type": "uiOverride", "params": { "propertyOwn[this]": { "rentalIncome": { "classNames": "col-lg-4 visible" }, "netRentalIncome": { "classNames": "col-lg-6 visible" } } } } }

I've opened - RXNT/json-rules-engine-simplified#29, so that you could have indexes of matched elements in event, and act as needed, but I'm not sure when this will be implemented.
This way you would be able to write your own uiOverride action, that would apply this changes appropriately.

Hey @mavarazy
I am using this library and got stumbled upon a similar issue like @deepan-itela . I have an array with object items that include specific conditions. Those objects are not always the same because I dynamically have to generate them based on data I got from an API service. Because of that it is hard to create generic custom field for this array as you suggested (different fields, different conditions, etc..).

Anyway, I started to take into consideration the option to make PRs on both libraries (json-rules-engine-simplified & react-jsonschema-form-conditional) for supporting conditions within array items. As you understand the problem and the required actions for making this possible, I would like to ask you if you can write down some helpful tips and agenda what should be implemented on those libraries. Thanks!