fix(field): cleaned up old register code
This commit is contained in:
parent
085895ee94
commit
95a9ce7b0b
3 changed files with 2 additions and 54 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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}>
|
||||
<${childFormGroupTag} name="child[]"></${childFormGroupTag}>
|
||||
</${formGroupTag}>
|
||||
`);
|
||||
expect(parentFormEl.resetModelValue.length).to.equal(2);
|
||||
parentFormEl.removeChild(parentFormEl.children[0]);
|
||||
expect(parentFormEl.resetModelValue.length).to.equal(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue