-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Placeholder width bug with multiselect2 #4323
Comments
I wasn't able to reproduce this in the examples page, but I also may have misinterpreted the issue. Can you expand upon the issue you are facing by adding a few more pieces of information to your bug report?
The contributing guide contains a useful section with a few questions which can help us track down the bug and speed up the process of finding a fix for it. The creation of an isolated test case would also be useful. |
Here is your jsfiddle: https://jsfiddle.net/km1adzaq/ The second field-set doesn't shows full placeholder |
Yes, I saw this problem too. An example is to put a select2 control in a tab which is initially not active, and then when activate that tab, you see the select2 placeholder only partially displayed. Is there any fix or workaround available? Thanks |
Here is a simple example of the problem http://jsfiddle.net/say2rwmt/4/ using bootstrap tabs to initially hide the select2. When you click the second tab, you'll see the placeholder is truncated. Note: as soon as you enter text, and backspace, the placeholder resets to it's correct size. A workaround for this specific instance is to hook into the tab shown event and (re)initialize select2: |
Haven't had time for much testing but possible fix/workaround around line 2005 (in select2.min.js): Original fiddle (with problem): http://jsfiddle.net/say2rwmt/4/ Original: if (this.$search.attr('placeholder') !== '') {
width = this.$selection.find('.select2-selection__rendered').innerWidth();
} else { changed to: if (this.$search.attr('placeholder') !== '') {
width = this.$element.width() === 1 ? this.$selection.width() : this.$element.width();
} else { |
|
I've come across the same issue too, except I'm drawing the select2 elements on page load. I've noticed also that even if you replace the placeholder's length of 100px with 100% it still doesn't display correctly since the wrapping li doesn't span the whole line (specifically the li with the select2-search select2-search--inline which requires the following class in the CSS to have The remaining issue then is that the final input box inside of the above li is being set to 100px via inline styling and thus can't be overwritten in the CSS file. I'll look to see if I can spot where it's being applied to the input. |
Also worth noting that If you select a value then remove it, then the correct width does get applied to the placeholder instead of the 100px. Could it be that the width is being gotten before the select box has been drawn on the DOM leading to a default value being used instead? So that when the values are changed and then blanked, the select box is present and a correct width can then be applied? Just a hunch at any rate. Finally as a side note, I tried seeing exactly where the placeholder triggers the width value functions (of which there are a few) but the only one that default to 'px' weren't being triggered. Quite confusing really. |
Same issue, my css solution: |
Thanks @dellch , i fixed this in my end by your code. |
@Cruiser13 's solution worked for me, but I also had to include the li element:
|
This is a duplicate of #291, so please continue any further discussion there. |
In the lastest version of select2, If a select is not visible when select2 init it, the select2 will not have the width of the select but will have always 100% and the placeholder will always have 100px. Why ?
Also, i'm able to reproduce it on your website, in the examples section.
The text was updated successfully, but these errors were encountered: