When i am editing the jsonforms with previously saved answers and i modify the answer, now in the form response i can see both previously saved answer and new answer

const schema = {
“type”: “object”,
“properties”: {
“eligibility”: {
“type”: “string”,
“enum”: [“Yes”, “No”]
},
“participation”: {
“type”: “string”,
“enum”: [“Yes”, “No”],
},
“futureParticipation”: {
“type”: “string”,
“enum”: [“Yes”, “No”],
},
“reconsiderFutureParticipation”: {
“type”: “string”,
“enum”: [“1 month”, “2 months”, “3 months”, “4 months”, “5 months”, “6 months”, “7 months”, “8 months”, “9 months”, “10 months”, “11 months”, “12 months”]
},
“nonParticipationOtherReason”: {
“type”: “string”
},
“disqualificationReason”: {
“type”: “string”,
“enum”: [“Reason 1”, “Reason 2”, “Reason 3”, “Reason 4”, “Reason 5”, “Reason 6”],
},
“disqualificationOtherReason”: {
“type”: “string”
},
}
};

const uischema = {
“type”: “VerticalLayout”,
“elements”: [
{
“type”: “Group”,
“elements”: [
{
“type”: “Control”,
“label”: “Was the patient eligible for program?”,
“scope”: “#/properties/eligibility”,
“options”: {
“format”: “radio”
}
},
{
“type”: “Control”,
“label”: “Will the patient participate in the program?”,
“scope”: “#/properties/participation”,
“options”: {
“format”: “radio”
},
“rule”: {
“effect”: “ENABLE”,
“condition”: {
“scope”: “#/properties/eligibility”,
“schema”: {
“const”: “Yes”
}
}
}
},
{
“type”: “Control”,
“label”: “Did the patient express interest in reconsidering in the future?”,
“scope”: “#/properties/futureParticipation”,
“options”: {
“format”: “radio”
},
“rule”: {
“effect”: “SHOW”,
“condition”: {
“scope”: “#”,
“schema”: {
“properties”: {
“participation”: {
“const”: “No”
},
“eligibility”: {
“const”: “Yes”
}
},
“required”: [
“participation”,
“eligibility”
]
}
}
}
},
{
“type”: “Control”,
“label”: “Suppress additional alerts until:”,
“scope”: “#/properties/reconsiderFutureParticipation”,
“rule”: {
“effect”: “SHOW”,
“condition”: {
“scope”: “#”,
“schema”: {
“properties”: {
“futureParticipation”: {
“const”: “Yes”
},
“eligibility”: {
“const”: “Yes”
},
“participation”: {
“const”: “No”
}
},
“required”: [
“futureParticipation”,
“eligibility”,
“participation”
]
}
}
}
},
{
“type”: “Control”,
“label”: “Why was the patient not eligible for program?”,
“scope”: “#/properties/disqualificationReason”,
“rule”: {
“effect”: “SHOW”,
“condition”: {
“scope”: “#/properties/eligibility”,
“schema”: {
“const”: “No”
}
}
}
},
{
“type”: “Control”,
“label”: “disqualificationOtherReason”,
“scope”: “#/properties/disqualificationOtherReason”,
“rule”: {
“effect”: “SHOW”,
“condition”: {
“scope”: “#”,
“schema”: {
“properties”: {
“disqualificationReason”: {
“const”: “Other”
},
“eligibility”: {
“const”: “No”
}
},
“required”: [
“disqualificationReason”,
“eligibility”
]
}
}
}
}
]
}
]
};

    <div>
        <JsonForms
            schema={schema}
            data={filteredData}
            uischema={uischema}
            renderers={materialRenderers}
            cells={materialCells}
            onChange={({ data, errors }) => {
                console.log({ data })
                if (JSON.stringify(data) !== JSON.stringify(formData)) {
                    setFormData(data)
                }
            }}
        />
    </div>

to data props i am passing this object
{
“eligibility”: “No”,
“participation”: “No”,
“disqualificationReason”: “Reason 1”
}

now i choose Yes as answer for this question
“Was the patient eligible for program?”

now the expected form response is
{
“eligibility”: “Yes”,
“participation”: “No”
}

but what i am getting is
{
“eligibility”: “Yes”,
“participation”: “No”,
“disqualificationReason”: “Reason 1”
}
This is the problem i am facing.

Hi @Suriyan ,

now i choose Yes as answer for this question
“Was the patient eligible for program?”

now the expected form response is
{
“eligibility”: “Yes”,
“participation”: “No”
}

but what i am getting is
{
“eligibility”: “Yes”,
“participation”: “No”,
“disqualificationReason”: “Reason 1”
}

The current behavior is the expected default behavior: When you select “Yes” for the “eligibility” property, only its value is changed. All others are kept as they are. Thus, the “disqualificationReason” value won’t change.

To change other properties in the data when a data change occurs (like in your case), you can provide a middleware. In your case the middleware could clear the “disqualificationReason” property whenever “eligibility” is changed to “Yes”. Find the official middleware documentation here: https://jsonforms.io/docs/middleware

Hi @lucas-koehler ,
Thanks for the update, i was able to add middleware and clear the data.

1 Like