Editor dependent - Check Value of multiple fields
Editor dependent - Check Value of multiple fields
Hi everybody,
I have the following problem: I have three dropdown fields "field_1", "field_2" and "field_3". For all three fields either "Ja" or "Nein" can be selected as the value. In addition, all three fields have a placeholder "Bitte auswählen".
Now I want that if the value "Nein" is selected for all three fields (field_1, field_2 and field_3), the fields 4-12 are displayed in the editor. In all other situations the fields 4-12 should be hidden and their value should be set to " ".
I have used editor.dependent for this. But now I have the problem that my code does not work, because if I select the value "Nein" for all the three fields (field_1, field_2 and field_3), the fields 4-12 are still hidden and the values are set to " ".
Does anyone have an idea what I made wrong?
Code for the three editor fields:
{
"label": "Field 1?<sup>*</sup>",
"name": "field_1",
"type": "select",
"placeholder": "Bitte auswählen",
"options": [
'Ja',
'Nein',
]
},
{
"label": "Field 2?<sup>*</sup>",
"name": "field_2",
"type": "select",
"placeholder": "Bitte auswählen",
"options": [
'Ja',
'Nein',
]
},
{
"label": "Field 3?<sup>*</sup>",
"name": "field_3",
"type": "select",
"placeholder": "Bitte auswählen",
"options": [
'Ja',
'Nein',
]
},
Code for editor dependent:
editor.dependent( 'field_1', function ( val) {
if (val === "Nein" && val['field_2'] === "Nein" && val['field_3'] === "Nein") {
return {
show: [
'field_4',
'field_5',
'field_6',
'field_7',
'field_8',
'field_9',
'field_10',
'field_11',
'field_12',
]
};
}
else {
return {
hide: [
'field_4',
'field_5',
'field_6',
'field_7',
'field_8',
'field_9',
'field_10',
'field_11',
'field_12',
],
values: {
'field_4': "",
'field_5': "",
'field_6': "",
'field_7': "",
'field_8': "",
'field_9': "",
'field_10': "",
'field_11': "",
'field_12': "",
}
};
}
});
Best regards
Schwaluck
This question has an accepted answers - jump to answer
Answers
Hey everybody,
I found the solution. I just needed to change the if clause like the following:
Maybe this will help someone else in the future.
Thank you. It was helpful.