Skip to content

Commit 83813f2

Browse files
Preserve fieldset nested fields visibility
1 parent 3560c4c commit 83813f2

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/helpers.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,25 @@ function updateField(field, requiredFields, node, formValues, logic, config) {
243243
field.isVisible = true;
244244
}
245245

246+
// Store current visibility of fields within a fieldset before updating its attributes
247+
const nestedFieldsVisibility = field.fields?.reduce?.((acc, f) => {
248+
acc[f.name] = f.isVisible;
249+
return acc;
250+
}, {});
251+
246252
const updateAttributes = (fieldAttrs) => {
247253
Object.entries(fieldAttrs).forEach(([key, value]) => {
248254
field[key] = value;
249255

256+
// If the field is a fieldset, restore the visibility of the fields within it.
257+
// If this is not in place, calling updateField for multiple conditionals touching
258+
// the same fieldset will unset previously calculated visibility for the nested fields.
259+
if (key === 'fields' && !isNil(nestedFieldsVisibility)) {
260+
field.fields.forEach((f) => {
261+
f.isVisible = nestedFieldsVisibility[f.name];
262+
});
263+
}
264+
250265
if (key === 'schema' && typeof value === 'function') {
251266
// key "schema" refers to YupSchema that needs to be processed for validations.
252267
field[key] = value();

0 commit comments

Comments
 (0)