Skip to content

Commit b3295f6

Browse files
Preserve fieldset nested fields visibility
1 parent c670cbe commit b3295f6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/helpers.js

+15
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,25 @@ function updateField(field, requiredFields, node, formValues, logic, config) {
242242
field.isVisible = true;
243243
}
244244

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

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

0 commit comments

Comments
 (0)