Skip to content

Commit fe2ce2e

Browse files
committedJun 26, 2023
Fix for select2 sizing #189
1 parent 44df7ff commit fe2ce2e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed
 

‎grails-app/assets/javascripts/forms-knockout-bindings.js

+17-2
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,22 @@
459459
if ($parentColumn.length) {
460460
var select2 = $parentColumn.find('.select2-container');
461461
function calculateWidth() {
462-
var columnWidth = $parentTable.width()*percentageWidth/100;
462+
var parentWidth = $parentTable.width();
463+
464+
// If the table has overflowed due to long selections then we need to try and find a parent div
465+
// as the div won't have overflowed.
466+
var windowWidth = window.innerWidth;
467+
if (parentWidth > windowWidth) {
468+
var parent = $parentTable.parent('div');
469+
if (parent.length) {
470+
parentWidth = parent.width();
471+
}
472+
else {
473+
parentWidth = windowWidth;
474+
}
475+
}
476+
var columnWidth = parentWidth*percentageWidth/100;
477+
463478
if (columnWidth > 10) {
464479
select2.css('max-width', columnWidth+'px');
465480
}
@@ -477,7 +492,7 @@
477492
ko.utils.domNodeDisposal.addDisposeCallback(element, function() {
478493
$(window).off('resize', resizeHandler);
479494
});
480-
setTimeout(calculateWidth, 100);
495+
setTimeout(calculateWidth, 0);
481496
}
482497

483498
}

0 commit comments

Comments
 (0)