Skip to content

Commit 21f6d5f

Browse files
committed
Merge branch 'aravindpanicker-rich-select-fix'
2 parents 4593320 + 81f4924 commit 21f6d5f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

src/components/TRichSelect.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ const TRichSelect = MultipleInput.extend({
186186
query: '',
187187
filteredOptions: [] as NormalizedOptions,
188188
selectedOption: undefined as undefined | NormalizedOption,
189-
selectedOptions: [] as NormalizedOption[],
189+
selectedOptions: [] as NormalizedOptions,
190190
searching: false,
191191
delayTimeout: undefined as undefined | ReturnType<typeof setTimeout>,
192192
nextPage: undefined as undefined | number,
@@ -198,7 +198,7 @@ const TRichSelect = MultipleInput.extend({
198198
if (Array.isArray(this.value)) {
199199
this.selectedOptions = this.value
200200
.map((value) => this.findOptionByValue(value))
201-
.filter((option) => !!option) as NormalizedOption[];
201+
.filter((option) => !!option) as NormalizedOptions;
202202
} else if (!this.selectedOption || this.selectedOption.value !== this.value) {
203203
this.selectedOption = this.findOptionByValue(this.value);
204204
}
@@ -228,7 +228,7 @@ const TRichSelect = MultipleInput.extend({
228228
if (Array.isArray(localValue)) {
229229
this.selectedOptions = localValue
230230
.map((value) => this.findOptionByValue(value))
231-
.filter((option) => !!option) as NormalizedOption[];
231+
.filter((option) => !!option) as NormalizedOptions;
232232
} else if (!this.selectedOption || this.selectedOption.value !== localValue) {
233233
this.selectedOption = this.findOptionByValue(localValue);
234234
}
@@ -278,7 +278,7 @@ const TRichSelect = MultipleInput.extend({
278278
},
279279

280280
computed: {
281-
usesAJax(): boolean {
281+
usesAjax(): boolean {
282282
return !!this.fetchOptions;
283283
},
284284
shouldShowSearchbox(): boolean {
@@ -289,7 +289,7 @@ const TRichSelect = MultipleInput.extend({
289289
const hasminimumResultsForSearch: boolean = hasMinResultsSetting
290290
|| hasQuery
291291
|| (
292-
this.usesAJax
292+
this.usesAjax
293293
? this.filteredflattenedOptions.length >= this.minimumResultsForSearch
294294
: this.normalizedOptions.length >= this.minimumResultsForSearch
295295
);
@@ -359,6 +359,15 @@ const TRichSelect = MultipleInput.extend({
359359
methods: {
360360
// eslint-disable-next-line max-len
361361
findOptionByValue(value: string | number | boolean | symbol | null): undefined | NormalizedOption {
362+
if (this.usesAjax) {
363+
// When using ajax results the filtered options are that ones that were
364+
// fetched with the `fetchOptions` method. Since those can change, we
365+
// also need to check the `selectedOptions` array that contains the
366+
// already selected ones.
367+
return [...this.filteredflattenedOptions, ...this.selectedOptions]
368+
.find((option) => this.optionHasValue(option, value));
369+
}
370+
362371
return this.flattenedOptions
363372
.find((option) => this.optionHasValue(option, value));
364373
},
@@ -627,7 +636,7 @@ const TRichSelect = MultipleInput.extend({
627636

628637
const endReached = nextOptionIndex >= this.filteredflattenedOptions.length;
629638

630-
if (endReached && this.usesAJax && this.nextPage) {
639+
if (endReached && this.usesAjax && this.nextPage) {
631640
this.listEndReached();
632641
} else {
633642
this.highlighted = nextOptionIndex;

0 commit comments

Comments
 (0)