Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/components/select/Select.js
Original file line number Diff line number Diff line change
Expand Up @@ -996,9 +996,13 @@ export default class SelectComponent extends ListComponent {
if (!input) {
return;
}
this.addEventListener(input, this.inputInfo.changeEvent, () => this.updateValue(null, {
modified: true
}));

if (this.component.widget !== "html5") {
this.addEventListener(input, this.inputInfo.changeEvent, () => this.updateValue(null, {
modified: true
}));
}

this.attachRefreshOnBlur();

if (this.component.widget === 'html5') {
Expand All @@ -1023,6 +1027,16 @@ export default class SelectComponent extends ListComponent {
}
});

this.addEventListener(input, 'change', (event) => {
let value = event.target.value;

if (this.component.multiple) {
value = Array.from(event.target.selectedOptions).map(opt => opt.value);
}

this.setValue(value, { modified: true });
});

return;
}

Expand Down Expand Up @@ -1513,6 +1527,11 @@ export default class SelectComponent extends ListComponent {
}

updateValue(value, flags) {
if (this.component.widget === 'html5' && this.component.multiple) {
if (!Array.isArray(value)) {
value = value != null && value !== '' ? [value] : [];
}
}
const changed = super.updateValue(value, flags);
if (changed || !this.selectMetadata || flags.resetValue) {
if (this.component.multiple && Array.isArray(this.dataValue)) {
Expand Down Expand Up @@ -1545,6 +1564,12 @@ export default class SelectComponent extends ListComponent {
}

setValue(value, flags = {}) {
if (this.component.widget === 'html5' && this.component.multiple) {
if (!Array.isArray(value)) {
value = value != null && value !== '' ? [value] : [];
}
}

const previousValue = this.dataValue;
const changed = this.updateValue(value, flags);
if (this.component.widget === 'html5' && (_.isEqual(value, previousValue) || _.isEqual(previousValue, {}) && _.isEqual(flags, {})) && !flags.fromSubmission ) {
Expand Down