Skip to content

Commit b7cdbc4

Browse files
IBX-11260: Fixed dropdown lazy initialization for dynamically populated translation selects (#1834)
* Fixed dropdown lazy initialization for dynamically populated translation selects * [Tests] Fixed failing test --------- Co-authored-by: Tomasz Kryszan <tomasz.kryszan@ibexa.co>
1 parent a77e78c commit b7cdbc4

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

src/bundle/Resources/public/js/scripts/core/dropdown.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@
6060
this.itemTemplate = this.itemsListContainer.dataset.template;
6161
this.sourceOptionsObserver = new MutationObserver((mutationsList) => {
6262
if (this.hasChangedOptions(mutationsList)) {
63+
const optionsCount = this.sourceInput.querySelectorAll('option').length;
64+
65+
if (optionsCount && !this.itemsPopover) {
66+
this.initializeDropdownUI();
67+
}
68+
6369
this.recreateOptions();
6470
}
6571
});
@@ -91,6 +97,7 @@
9197
this.itemsPopoverContent = this.itemsPopoverContent.bind(this);
9298
this.onSourceFocus = this.onSourceFocus.bind(this);
9399
this.onSourceBlur = this.onSourceBlur.bind(this);
100+
this.initializeDropdownUI = this.initializeDropdownUI.bind(this);
94101

95102
ibexa.helpers.objectInstances.setInstance(this.container, this);
96103
}
@@ -530,21 +537,8 @@
530537
this.selectionTogglerBtn.innerHTML = label;
531538
}
532539

533-
init() {
534-
if (this.container.dataset.initialized) {
535-
console.warn('Dropdown has already been initialized!');
536-
537-
return;
538-
}
539-
540-
this.container.dataset.initialized = true;
541-
542-
this.sourceInput.addEventListener('focus', this.onSourceFocus, false);
543-
this.sourceInput.addEventListener('blur', this.onSourceBlur, false);
544-
545-
const optionsCount = this.container.querySelectorAll('.ibexa-dropdown__source option').length;
546-
547-
if (!optionsCount) {
540+
initializeDropdownUI() {
541+
if (this.itemsPopover) {
548542
return;
549543
}
550544

@@ -610,7 +604,19 @@
610604
this.itemsFilterInput.addEventListener('keyup', this.filterItems, false);
611605
this.itemsFilterInput.addEventListener('input', this.filterItems, false);
612606
}
607+
}
613608

609+
init() {
610+
if (this.container.dataset.initialized) {
611+
console.warn('Dropdown has already been initialized!');
612+
613+
return;
614+
}
615+
616+
this.container.dataset.initialized = true;
617+
618+
this.sourceInput.addEventListener('focus', this.onSourceFocus, false);
619+
this.sourceInput.addEventListener('blur', this.onSourceBlur, false);
614620
this.sourceOptionsObserver.observe(this.sourceInput, {
615621
childList: true,
616622
});
@@ -620,6 +626,14 @@
620626
});
621627
this.resizeObserver.observe(this.container);
622628

629+
const optionsCount = this.container.querySelectorAll('.ibexa-dropdown__source option').length;
630+
631+
if (!optionsCount) {
632+
return;
633+
}
634+
635+
this.initializeDropdownUI();
636+
623637
const selectedItems = this.container.querySelectorAll(
624638
'.ibexa-dropdown__selected-item:not(.ibexa-dropdown__selected-overflow-number):not(.ibexa-dropdown__selected-placeholder)',
625639
);

tests/lib/Form/Data/Role/RoleAssignmentCreateDataValidationTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ public static function getDataForTestFormSubmitValidation(): iterable
5454
['{{ value }}' => 'foo'],
5555
'children[limitation_type]'
5656
),
57-
new FormErrorDataTestWrapper(
58-
'The selected choice is invalid.',
59-
['{{ value }}' => 'foo'],
60-
'children[limitation_type]'
61-
),
6257
],
6358
];
6459

0 commit comments

Comments
 (0)