Skip to content

Commit 86d31a4

Browse files
committed
feat(MultiSelect): add the ability to set a custom name attribute for the native select element
1 parent f089ca5 commit 86d31a4

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

docs/content/forms/multi-select.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,18 @@ You may also choose from small and large multi selects to match our similarly si
226226
| `cleaner`| boolean| `true` | Enables selection cleaner element. |
227227
| `disabled` | boolean | `false` | Toggle the disabled state for the component. |
228228
| `invalid` | boolean | `false` | Toggle the invalid state for the component. |
229-
| `options` | (boolean\|array)| `false` | List of option elements. |
230-
| `optionsMaxHeight` | (number\|string)| `'auto'` | Sets `max-height` of options list. |
231-
| `optionsStyle` | string| `'checkbox'` | Sets option style. |
232-
| `placeholder` | string| `'Select...'` | Specifies a short hint that is visible in the input. |
233-
| `search` | boolean| `false` | Enables search input element. |
234-
| `searchNoResultsLabel` | string| `'No results found'` | Sets the label for no results when filtering. |
235-
| `selectAll` | boolean| `true` | Enables select all button.|
236-
| `selectAllLabel` | string| `'Select all options'` | Sets the select all button label. |
237-
| `selectionType` | string| `'tag'` | Sets the selection style. |
238-
| `selectionTypeCounterText` | string| `'item(s) selected'` | Sets the counter selection label. |
229+
| `multiple` | boolean | `true` | It specifies that multiple options can be selected at once. |
230+
| `name` | string | `null` | Set the name attribute for the native select element. |
231+
| `options` | (boolean\|array) | `false` | List of option elements. |
232+
| `optionsMaxHeight` | (number\|string) | `'auto'` | Sets `max-height` of options list. |
233+
| `optionsStyle` | string | `'checkbox'` | Sets option style. |
234+
| `placeholder` | string | `'Select...'` | Specifies a short hint that is visible in the input. |
235+
| `search` | boolean | `false` | Enables search input element. |
236+
| `searchNoResultsLabel` | string | `'No results found'` | Sets the label for no results when filtering. |
237+
| `selectAll` | boolean | `true` | Enables select all button.|
238+
| `selectAllLabel` | string | `'Select all options'` | Sets the select all button label. |
239+
| `selectionType` | string | `'tag'` | Sets the selection style. |
240+
| `selectionTypeCounterText` | string | `'item(s) selected'` | Sets the counter selection label. |
239241
| `valid` | boolean | `false` | Toggle the valid state for the component. |
240242
{{< /bs-table >}}
241243

js/src/multi-select.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,12 @@ const Default = {
7575
disabled: false,
7676
invalid: false,
7777
multiple: true,
78-
placeholder: 'Select...',
79-
required: false,
78+
name: null,
8079
options: false,
8180
optionsMaxHeight: 'auto',
8281
optionsStyle: 'checkbox',
82+
placeholder: 'Select...',
83+
required: false,
8384
search: false,
8485
searchNoResultsLabel: 'No results found',
8586
selectAll: true,
@@ -94,11 +95,12 @@ const DefaultType = {
9495
disabled: 'boolean',
9596
invalid: 'boolean',
9697
multiple: 'boolean',
97-
placeholder: 'string',
98-
required: 'boolean',
98+
name: 'string',
9999
options: '(boolean|array)',
100100
optionsMaxHeight: '(number|string)',
101101
optionsStyle: 'string',
102+
placeholder: 'string',
103+
required: 'boolean',
102104
search: 'boolean',
103105
searchNoResultsLabel: 'string',
104106
selectAll: 'boolean',
@@ -448,8 +450,8 @@ class MultiSelect extends BaseComponent {
448450
this._updateSearch()
449451
}
450452

451-
if (this._element.id) {
452-
this._element.setAttribute('name', `multi-select-${this._element.id}`)
453+
if (this._config.name || this._element.id || this._element.name) {
454+
this._element.setAttribute('name', (this._config.name || this._element.name || `multi-select-${this._element.id}`))
453455
}
454456

455457
this._createOptionsContainer()

0 commit comments

Comments
 (0)