Hidden data is not removed from redux store

Hi JSONForms community

Im debugging a form of ours that consists of multiple sections. Most of these section starts with a simple yes/no question think of like a toggle button(standard_main_question in the schema below).
The state of the toggle(true or false) is used to show additional questions using the Rules API as written in the docs.

However if I choose to toggle yes and answer those questions but then decide to toggle no.
Those hidden questions(standard_main_question_additional_question_1 and standard_main_question_additional_question_2) are still being submitted to the backend and they still remain inside the redux store even though they are now hidden due to I changed my toggle to no.
I did go through the list of issues on Github and found something related(I think).

I know it can be hard without the actual schema but I can post this here as well. Whats the best way to do so? A gist or directly in the spectrum?

Schema:

{
“type”: “VerticalLayout”,
“elements”: [
{
“type”: “Section”,
“label”: “TITLE_HERE”,
“description”: “”,
“elements”: [
{
“type”: “ToggleControl”,
“scope”: “#/properties/standard/properties/standard_main_question”
},
{
“type”: “Group”,
“elements”: [
{
“type”: “Control”,
“scope”: “#/properties/standard/properties/standard_main_question_additional_question_1”,
“options”: {
“multi”: true
}
},
{
“type”: “Control”,
“scope”: “#/properties/standard/properties/standard_main_question_additional_question_2”
}
],
“rule”: {
“effect”: “SHOW”,
“condition”: {
“scope”: “#/properties/standard/properties/standard_main_question”,
“schema”: {
“const”: true
}
}
}
}
]
}

[original thread by Steffen Thomsen]

Hi @steffen25(steffen25), we don’t remove data by design, we just show or hide the controls. Usually the experience is not that great when the user enters some data, triggers a hide rule (for example by clicking a check box), then untriggers it (unchecking the checkbox) and now has to reenter all of their data again.

Usually I recommend just removing the unwanted data before further processing it, e.g. before sending it to a REST endpoint.

Of course you can still achieve this effect if you want to:

  • Register a custom renderer for the control which effectively hides/unhides the other controls. There not only set your own data but also remove the data you don’t want to keep, or

  • Register a middleware which listens to these specific data changes you are interested in and also removes the data you don’t want to keep

Thank You for the the detailed response.

You said

I recommend just removing the unwanted data before further processing

I want to filter hidden fields before submitting the form. is it possible?
Otherwise I cannot understand what data is unwanted.

Hi @Ollemesh,

This is not a feature which is currently supported by JSON Forms. We generally avoid manipulating data just by rendering, which is why this feature is not offered.

You could either do a post-processing step yourself to filter all unwanted data, or customize the JSON Forms bindings to adapt the data on the fly when it’s marked visible: false by JSON Forms.

Note that this has all kinds of hidden traps, for example if you simply don’t include a field in the UI Schema it will also not shown in the UI and you might expect that it’s also not contained in the data. However as JSON Forms never processed that field in question you will also not get a visible: false for it. So in case it was part of the original data passed in to JSON Forms then it will also be there later.