Skip to content

Commit e8fce4d

Browse files
committed
bug #1513 [Autocomplete] Fix regression where placeholder change didn't cause a reset (weaverryan)
This PR was merged into the 2.x branch. Discussion ---------- [Autocomplete] Fix regression where placeholder change didn't cause a reset | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | Issues | None | License | MIT Introduced here - https://github.com/symfony/ux/pull/1502/files#diff-655bee3f1f3d92a2b984a8599df80a4f31a842d5f04fd3d186f8e3161ce49c0bR429 - when fixing the bug: > A) If there was no empty <option value""> element, then each time a value was selected, it incorrectly looked like the options had changed, triggering a reset. This is because TomSelect adds a `<option value="">` is there was not one at the start. Commits ------- d81648b [Autocomplete] Fix regression where placeholder change didn't cause a reset
2 parents 5688875 + d81648b commit e8fce4d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Autocomplete/assets/dist/controller.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ class default_1 extends Controller {
199199
areOptionsEquivalent(newOptions) {
200200
const filteredOriginalOptions = this.originalOptions.filter((option) => option.value !== '');
201201
const filteredNewOptions = newOptions.filter((option) => option.value !== '');
202+
const originalPlaceholderOption = this.originalOptions.find((option) => option.value === '');
203+
const newPlaceholderOption = newOptions.find((option) => option.value === '');
204+
console.log(originalPlaceholderOption, newPlaceholderOption);
205+
if (originalPlaceholderOption &&
206+
newPlaceholderOption &&
207+
originalPlaceholderOption.text !== newPlaceholderOption.text) {
208+
return false;
209+
}
202210
if (filteredOriginalOptions.length !== filteredNewOptions.length) {
203211
return false;
204212
}

src/Autocomplete/assets/src/controller.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,17 @@ export default class extends Controller {
429429
const filteredOriginalOptions = this.originalOptions.filter((option) => option.value !== '');
430430
const filteredNewOptions = newOptions.filter((option) => option.value !== '');
431431

432+
const originalPlaceholderOption = this.originalOptions.find((option) => option.value === '');
433+
const newPlaceholderOption = newOptions.find((option) => option.value === '');
434+
console.log(originalPlaceholderOption, newPlaceholderOption);
435+
if (
436+
originalPlaceholderOption &&
437+
newPlaceholderOption &&
438+
originalPlaceholderOption.text !== newPlaceholderOption.text
439+
) {
440+
return false;
441+
}
442+
432443
if (filteredOriginalOptions.length !== filteredNewOptions.length) {
433444
return false;
434445
}

0 commit comments

Comments
 (0)