fix(form-core): prevent choice input from changing name away from parent
This commit is contained in:
parent
fd297a2832
commit
e25586e606
2 changed files with 28 additions and 0 deletions
|
|
@ -110,6 +110,17 @@ const ChoiceInputMixinImplementation = superclass =>
|
||||||
if (changedProperties.has('modelValue')) {
|
if (changedProperties.has('modelValue')) {
|
||||||
this.__syncCheckedToInputElement();
|
this.__syncCheckedToInputElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
changedProperties.has('name') &&
|
||||||
|
// @ts-expect-error not all choice inputs have a parent form group, since this mixin does not have a strict contract with the registration system
|
||||||
|
this.__parentFormGroup &&
|
||||||
|
// @ts-expect-error
|
||||||
|
this.__parentFormGroup.name !== this.name
|
||||||
|
) {
|
||||||
|
// @ts-expect-error not all choice inputs have a name prop, because this mixin does not have a strict contract with form control mixin
|
||||||
|
this.name = changedProperties.get('name');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,23 @@ export function runChoiceGroupMixinSuite({ parentTagString, childTagString } = {
|
||||||
expect(el.formElements[1].name).to.equal('gender2');
|
expect(el.formElements[1].name).to.equal('gender2');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('prevents updating the name property of a child if it is different from its parent', async () => {
|
||||||
|
const el = /** @type {ChoiceGroup} */ (await fixture(html`
|
||||||
|
<${parentTag} name="gender">
|
||||||
|
<${childTag}></${childTag}>
|
||||||
|
<${childTag}></${childTag}>
|
||||||
|
</${parentTag}>
|
||||||
|
`));
|
||||||
|
|
||||||
|
expect(el.formElements[0].name).to.equal('gender');
|
||||||
|
expect(el.formElements[1].name).to.equal('gender');
|
||||||
|
|
||||||
|
el.formElements[0].name = 'gender2';
|
||||||
|
|
||||||
|
await el.formElements[0].updateComplete;
|
||||||
|
expect(el.formElements[0].name).to.equal('gender');
|
||||||
|
});
|
||||||
|
|
||||||
it('adjusts the name of a child element if it has a different name than the group', async () => {
|
it('adjusts the name of a child element if it has a different name than the group', async () => {
|
||||||
const el = /** @type {ChoiceGroup} */ (await fixture(html`
|
const el = /** @type {ChoiceGroup} */ (await fixture(html`
|
||||||
<${parentTag} name="gender">
|
<${parentTag} name="gender">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue