diff --git a/packages/field/src/FormRegisteringMixin.js b/packages/field/src/FormRegisteringMixin.js index a5b92e975..700cf2a7d 100644 --- a/packages/field/src/FormRegisteringMixin.js +++ b/packages/field/src/FormRegisteringMixin.js @@ -29,19 +29,14 @@ export const FormRegisteringMixin = dedupeMixin( __setupRegistrationHook() { if (formRegistrarManager.ready) { - this._registerFormElement(); + this._dispatchRegistration(); } else { formRegistrarManager.addEventListener('all-forms-open-for-registration', () => { - this._registerFormElement(); + this._dispatchRegistration(); }); } } - _registerFormElement() { - this._dispatchRegistration(); - this._requestParentFormGroupUpdateOfResetModelValue(); - } - _dispatchRegistration() { this.dispatchEvent( new CustomEvent('form-element-register', { @@ -56,16 +51,5 @@ export const FormRegisteringMixin = dedupeMixin( this.__parentFormGroup.removeFormElement(this); } } - - /** - * Makes sure our parentFormGroup has the most up to date resetModelValue - * FormGroups will call the same on their parentFormGroup so the full tree gets the correct - * values. - */ - _requestParentFormGroupUpdateOfResetModelValue() { - if (this.__parentFormGroup && this.__parentFormGroup._updateResetModelValue) { - this.__parentFormGroup._updateResetModelValue(); - } - } }, ); diff --git a/packages/field/src/LionField.js b/packages/field/src/LionField.js index 90b8b2ecb..ba4cf1bf3 100644 --- a/packages/field/src/LionField.js +++ b/packages/field/src/LionField.js @@ -122,14 +122,6 @@ export class LionField extends FormControlMixin( disconnectedCallback() { super.disconnectedCallback(); - - if (this.__parentFormGroup) { - const event = new CustomEvent('form-element-unregister', { - detail: { element: this }, - bubbles: true, - }); - this.__parentFormGroup.dispatchEvent(event); - } this.inputElement.removeEventListener('change', this._onChange); } diff --git a/packages/field/test-suites/FormRegistrationMixins.suite.js b/packages/field/test-suites/FormRegistrationMixins.suite.js index 948e6dc17..5db8bb5dd 100644 --- a/packages/field/test-suites/FormRegistrationMixins.suite.js +++ b/packages/field/test-suites/FormRegistrationMixins.suite.js @@ -117,33 +117,5 @@ export const runRegistrationSuite = customConfig => { el.removeChild(newField); expect(el.formElements.length).to.equal(1); }); - - describe('Unregister', () => { - it.skip('requests update of the resetModelValue function of its parent formGroup on unregister', async () => { - const ParentFormGroupClass = class extends FormRegistrarMixin(LitElement) { - _updateResetModelValue() { - this.resetModelValue = this.formElements.length; - } - }; - const ChildFormGroupClass = class extends FormRegisteringMixin(LitElement) { - constructor() { - super(); - this.__parentFormGroup = this.parentNode; - } - }; - - const formGroupTag = unsafeStatic(defineCE(ParentFormGroupClass)); - const childFormGroupTag = unsafeStatic(defineCE(ChildFormGroupClass)); - const parentFormEl = await fixture(html` - <${formGroupTag}> - <${childFormGroupTag} name="child[]"> - <${childFormGroupTag} name="child[]"> - - `); - expect(parentFormEl.resetModelValue.length).to.equal(2); - parentFormEl.removeChild(parentFormEl.children[0]); - expect(parentFormEl.resetModelValue.length).to.equal(1); - }); - }); }); };