Skip to content

Commit 085895e

Browse files
committed
fix(fieldset): reset / inital modelValue always accurate
1 parent 995e8f9 commit 085895e

File tree

2 files changed

+181
-117
lines changed

2 files changed

+181
-117
lines changed

packages/fieldset/src/LionFieldset.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const pascalCase = str => str.charAt(0).toUpperCase() + str.slice(1);
1111
/**
1212
* LionFieldset: fieldset wrapper providing extra features and integration with lion-field elements.
1313
*
14-
* @customElement
14+
* @customElement lion-fieldset
1515
* @extends LionLitElement
1616
*/
1717
export class LionFieldset extends FormRegistrarMixin(
@@ -176,7 +176,14 @@ export class LionFieldset extends FormRegistrarMixin(
176176
}
177177

178178
resetGroup() {
179-
this.modelValue = this.resetModelValue;
179+
this.formElementsArray.forEach(child => {
180+
if (typeof child.resetGroup === 'function') {
181+
child.resetGroup();
182+
} else if (typeof child.reset === 'function') {
183+
child.reset();
184+
}
185+
});
186+
180187
this.resetInteractionState();
181188
}
182189

@@ -245,7 +252,7 @@ export class LionFieldset extends FormRegistrarMixin(
245252
}
246253

247254
/**
248-
* Get's triggered by event 'validatin-done' which enabled us to handle 2 different situations
255+
* Gets triggered by event 'validation-done' which enabled us to handle 2 different situations
249256
* - react on modelValue change, which says something about the validity as a whole
250257
* (at least two checkboxes for instance) and nothing about the children's values
251258
* - children validatity states have changed, so fieldset needs to update itself based on that
@@ -348,23 +355,16 @@ export class LionFieldset extends FormRegistrarMixin(
348355
}
349356

350357
/**
351-
* Updates the resetModelValue of this fieldset and asks it's parent fieldset/group to also
352-
* update.
353-
* This is needed as the upgrade order is not guaranteed. We have 3 main cases:
354-
* 1. if `street-name` gets updated last then `address` and `details` needs to update their
355-
* resetModelValue to also incorporate the correct value of `street-name`/`address`.
356-
* 2. If `address` get updated last then it already has the correct `street-name` so it
357-
* requests an update only for `details`.
358-
* 3. If `details` get updated last nothing happens here as all data are up to date
359-
*
360-
* @example
361-
* <lion-fieldset name="details">
362-
* <lion-fieldset name="address">
363-
* <lion-input name="street-name" .modelValue=${'street 1'}>
358+
* Gathers initial model values of all children. Used
359+
* when resetGroup() is called.
364360
*/
365-
_updateResetModelValue() {
366-
this.resetModelValue = this.modelValue;
367-
this._requestParentFormGroupUpdateOfResetModelValue();
361+
get _initialModelValue() {
362+
return this._getFromAllFormElements('_initialModelValue');
363+
}
364+
365+
/** @deprecated */
366+
get resetModelValue() {
367+
return this._initialModelValue;
368368
}
369369

370370
/**

0 commit comments

Comments
 (0)