Skip to content
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

Default text for multiple select is being truncated #2480

Closed
jacksontong opened this issue Dec 2, 2015 · 13 comments · Fixed by #2880
Closed

Default text for multiple select is being truncated #2480

jacksontong opened this issue Dec 2, 2015 · 13 comments · Fixed by #2880
Labels

Comments

@jacksontong
Copy link

I'm using bootstrap and this is my html code:

<div class="form-group">
<select id="copyproposalpageform-proposal_ids" class="chosen" name="CopyProposalPageForm[proposal_ids][]" multiple="multiple" size="4">

</select>
</div>
$('.chosen').chosen({
    width: '100%'
});

The default text is being truncated
screen shot 2015-12-02 at 11 23 17 am
but after I clicked to the dropdown and click away, it back to normal

@tjschuck
Copy link
Member

tjschuck commented Dec 2, 2015

What browser, browser version, OS, and OS version are you using? And what version of Chosen? If not the latest version, does it still happen on the latest version?

Additionally, please link to a publicly accessible page (or a Fiddle) that shows the issue so we can attempt to reproduce.

Closing until more info is provided, then we'll reopen.

@tjschuck tjschuck closed this as completed Dec 2, 2015
@tjschuck
Copy link
Member

tjschuck commented Dec 2, 2015

/cc @mlettini

@mlettini
Copy link
Contributor

mlettini commented Dec 2, 2015

@tjschuck the width on that <input> is added by JS, I believe. Would also like to see a fiddle of this issue to see if it's something that can be fixed with just CSS or not.

@jacksontong
Copy link
Author

Hi @tjschuck

I'm really sorry that I didn't give enough information, I think it happens when jquery chosen is calling inside bootstrap modal. this is my fiddle link.

browser: Chrome 47.0.2526.73 (64-bit)
os: OS X El Capitan

Cheers

@tjschuck
Copy link
Member

tjschuck commented Dec 8, 2015

@tongtoanbs Thanks for following up -- reopened!

@tjschuck tjschuck reopened this Dec 8, 2015
@tjschuck
Copy link
Member

tjschuck commented Dec 8, 2015

And cc: @mlettini again — Fiddle provided.

@mlettini
Copy link
Contributor

mlettini commented Dec 8, 2015

@tjschuck @tongtoanbs Thanks for the fiddle!

This does indeed look to be a bug, and @tongtoanbs is probably correct that it has something to do with bootstrap. The issue is in JS and not CSS. That input is given a width from the JS, and the width is not long enough when the modal first opens.

I'm not even sure why we need an explicit width at first. width: 100% should work for the initial multi-chosen (before any options are selected), I think.

@jacksontong
Copy link
Author

Hi @mlettini

if I don't pass that option then the chosen dropdown won't showing up for me. fiddle link

@mlettini
Copy link
Contributor

mlettini commented Dec 9, 2015

@tongtoanbs I don't think it's anything you're doing. If you look at the input inside of the 0px-width chosen dropdown in your second fiddle, you can still see the bug of the input being 90px when it should be bigger.

@koenpunt koenpunt added the Sizing label Oct 1, 2016
@taleteller
Copy link

I stumbled on this issue while implementing chosen() on a dynamically created form for my webapp. There the placeholder text was truncated as above. Since there was no progress to this ticket in a whole year, I started to fiddle around for myself.

In Chosen.prototype.set_up_html I changed line 619 from

this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:25px;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');

to

this.container.html('<ul class="chosen-choices"><li class="search-field"><input type="text" value="' + this.default_text + '" class="default" autocomplete="off" style="width:100%;" /></li></ul><div class="chosen-drop"><ul class="chosen-results"></ul></div>');

replacing the initial width from 25px with 100%. Further I removed the call to this.search_field_scale(); in line 627 - which was useless anyway because the same function gets called inside this.results_build();, ran at line 636. However, since my solution is to avoid rescaling the input field during construction, i had to remove this call as well. Therefore removing line 854 from Chosen.prototype.results_build.

While testing the chosen() Field ran perfectly well for me on Firefox and Chrome. Maybe some Dev can do a more extensive testing of this solution to finally solve this ticket.

@jellisii
Copy link

I have stumbled upon this issue as well.

https://codepen.io/jellisii/pen/vgQeqz?editors=1111

In this particular instance, you'll notice that I have the width to 100%, which sidesteps the problem of when chosen is rendered while hidden, but still does have the placeholder being short.

@claracena
Copy link

Had the same problem after showing the select box (hidden by default). Just run $('.my_select_box').trigger('chosen:updated'); after showing the select box (usually after page load)

@tjschuck
Copy link
Member

tjschuck commented Sep 5, 2017

This was fixed in #2880 and has been released as part of version 1.8.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants