Skip to content

Commit b9ba3db

Browse files
Joren BroekemadaKmoR
authored andcommitted
fix(select-rich): set dynamically name prop on child option elements
1 parent 97265d0 commit b9ba3db

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/select-rich/src/LionSelectRich.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,12 @@ export class LionSelectRich extends OverlayMixin(
238238
* @override
239239
* @param {*} child
240240
*/
241-
addFormElement(child) {
241+
addFormElement(passedChild) {
242+
const child = passedChild;
243+
244+
// Set the name property on the option elements ourselves, for form serialization
245+
child.name = `${this.name}[]`;
246+
242247
super.addFormElement(child);
243248
// we need to adjust the elements being registered
244249
/* eslint-disable no-param-reassign */

packages/select-rich/test/lion-select-rich.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,23 @@ describe('lion-select-rich', () => {
2525
expect(el.hasAttribute('tabindex')).to.be.false;
2626
});
2727

28+
it('delegates the name attribute to its children options', async () => {
29+
const el = await fixture(html`
30+
<lion-select-rich name="foo">
31+
<lion-options slot="input">
32+
<lion-option .choiceValue=${10}>Item 1</lion-option>
33+
<lion-option .choiceValue=${20}>Item 2</lion-option>
34+
</lion-options>
35+
</lion-select-rich>
36+
`);
37+
38+
const optOne = el.querySelectorAll('lion-option')[0];
39+
const optTwo = el.querySelectorAll('lion-option')[1];
40+
41+
expect(optOne.name).to.equal('foo[]');
42+
expect(optTwo.name).to.equal('foo[]');
43+
});
44+
2845
describe('Invoker', () => {
2946
it('generates an lion-select-invoker if no invoker is provided', async () => {
3047
const el = await fixture(html`

0 commit comments

Comments
 (0)