mirror of
https://github.com/Choices-js/Choices.git
synced 2024-06-08 00:42:15 +02:00
Addressing issue #224
This commit is contained in:
parent
26d4c2304e
commit
721441f32d
1968
src/scripts/dist/choices.js
vendored
1968
src/scripts/dist/choices.js
vendored
File diff suppressed because it is too large
Load diff
2
src/scripts/dist/choices.js.map
vendored
2
src/scripts/dist/choices.js.map
vendored
File diff suppressed because one or more lines are too long
6
src/scripts/dist/choices.min.js
vendored
6
src/scripts/dist/choices.min.js
vendored
File diff suppressed because one or more lines are too long
|
@ -505,6 +505,13 @@ class Choices {
|
|||
|
||||
// If we have grouped options
|
||||
if (activeGroups.length >= 1 && this.isSearching !== true) {
|
||||
// If we have a placeholder choice along with groups
|
||||
const activePlaceholders = activeChoices.filter(
|
||||
activeChoice => activeChoice.placeholder === true && activeChoice.groupId === -1,
|
||||
);
|
||||
if (activePlaceholders.length >= 1) {
|
||||
choiceListFragment = this.renderChoices(activePlaceholders, choiceListFragment);
|
||||
}
|
||||
choiceListFragment = this.renderGroups(activeGroups, activeChoices, choiceListFragment);
|
||||
} else if (activeChoices.length >= 1) {
|
||||
choiceListFragment = this.renderChoices(activeChoices, choiceListFragment);
|
||||
|
@ -2628,6 +2635,19 @@ class Choices {
|
|||
this.isSearching = false;
|
||||
|
||||
if (passedGroups && passedGroups.length) {
|
||||
// If we have a placeholder option
|
||||
const placeholderChoice = this.passedElement.querySelector('option[placeholder]');
|
||||
if (placeholderChoice.parentNode.tagName === 'SELECT') {
|
||||
this._addChoice(
|
||||
placeholderChoice.value,
|
||||
placeholderChoice.innerHTML,
|
||||
placeholderChoice.selected,
|
||||
placeholderChoice.disabled,
|
||||
undefined,
|
||||
undefined,
|
||||
/* placeholder */ true,
|
||||
);
|
||||
}
|
||||
passedGroups.forEach((group) => {
|
||||
this._addGroup(group, (group.id || null));
|
||||
});
|
||||
|
@ -2657,24 +2677,28 @@ class Choices {
|
|||
|
||||
// Add each choice
|
||||
allChoices.forEach((choice, index) => {
|
||||
// Pre-select first choice if it's a single select
|
||||
if (this.isSelectOneElement) {
|
||||
// If there is a selected choice already or the choice is not
|
||||
// the first in the array, add each choice normally
|
||||
// Otherwise pre-select the first choice in the array
|
||||
const shouldPreselect = (!hasSelectedChoice || (hasSelectedChoice && index === 0));
|
||||
const isSelected = shouldPreselect ? true : choice.selected;
|
||||
const isDisabled = shouldPreselect ? false : choice.disabled;
|
||||
if (this.isSelectElement) {
|
||||
// If the choice is actually a group
|
||||
if (choice.choices) {
|
||||
this._addGroup(choice, choice.id || null);
|
||||
} else {
|
||||
// If there is a selected choice already or the choice is not
|
||||
// the first in the array, add each choice normally
|
||||
// Otherwise pre-select the first choice in the array if it's a single select
|
||||
const shouldPreselect = this.isSelectOneElement && !hasSelectedChoice && index === 0;
|
||||
const isSelected = shouldPreselect ? true : choice.selected;
|
||||
const isDisabled = shouldPreselect ? false : choice.disabled;
|
||||
|
||||
this._addChoice(
|
||||
choice.value,
|
||||
choice.label,
|
||||
isSelected,
|
||||
isDisabled,
|
||||
undefined,
|
||||
choice.customProperties,
|
||||
choice.placeholder,
|
||||
);
|
||||
this._addChoice(
|
||||
choice.value,
|
||||
choice.label,
|
||||
isSelected,
|
||||
isDisabled,
|
||||
undefined,
|
||||
choice.customProperties,
|
||||
choice.placeholder,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
this._addChoice(
|
||||
choice.value,
|
||||
|
|
Loading…
Reference in a new issue