@@ -84,4 +84,41 @@ function handleFocusOnSelect2Field(firstField){
8484 setTimeout(() => document.querySelector('.select2-container--open .select2-search__field').focus(), 100);
8585});
8686
87+ // When Select2 opens inside a repeatable row that is itself inside a modal,
88+ // add a specific class to the open container so CSS/positioning logic can target it.
89+ // Also remove the class on close.
90+ $(document).on('select2:open', function(e) {
91+ // The event target will be the original select element
92+ try {
93+ var $select = $(e.target);
94+ var $repeatable = $select.closest('.repeatable-element');
95+ var $modal = $select.closest('.modal');
96+
97+ if ($repeatable.length && $modal.length) {
98+ // Wait briefly for Select2 to render the dropdown container
99+ setTimeout(function() {
100+ var $openContainer = $('.select2-container--open');
101+ $openContainer.addClass('select2-in-modal-repeatable');
102+ }, 0);
103+ }
104+ } catch (err) {
105+ // fail silently
106+ }
107+ });
108+
109+ $(document).on('select2:close', function(e) {
110+ try {
111+ var $select = $(e.target);
112+ var $repeatable = $select.closest('.repeatable-element');
113+ var $modal = $select.closest('.modal');
114+
115+ if ($repeatable.length && $modal.length) {
116+ // remove the class from any open containers
117+ $('.select2-container--open').removeClass('select2-in-modal-repeatable');
118+ }
119+ } catch (err) {
120+ // fail silently
121+ }
122+ });
123+
87124@endverbatim
0 commit comments