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

container_width = 0px #2795

Closed
tavoarcila opened this issue Mar 15, 2017 · 3 comments
Closed

container_width = 0px #2795

tavoarcila opened this issue Mar 15, 2017 · 3 comments

Comments

@tavoarcila
Copy link

tavoarcila commented Mar 15, 2017

Hi, I'm using a very old template (janux) for a system I've. that template used 0.98 version of chosen, and the .trigger("chosen:updated") did not work,

I tried updating to latest version but it only show a very tiny button, so, after some research and debug I found out that AbstractChosen.prototype.container_width was returning 0px (zero)

To fix in my hurry to get it fixed I just did the following:
AbstractChosen.prototype.container_width = function() {
toReturn = "";
if (this.options.width != null) {
toReturn = this.options.width;
} else {
toReturn = "" + this.form_field.offsetWidth + "px";
}
if (toReturn=="" || toReturn=="0px")
toReturn = "150px";
return toReturn;
};

This fixed the tiny button problem displaying the select correctly and with the latest version .trigger("chosen:updated") work like a charm.

I hope you can find a most professional solution for the container_width issue. Thank you

NOTE: The chosen select I'm using is inside a modal window, maybe this helps,

Thank you in advance for your help

Gustavo Arcila

@walter-gonzalez
Copy link

I have a similar issue with the container width being set to width=0px; in the style attribute.

@mr-KVA
Copy link

mr-KVA commented Jul 31, 2017

Hi, have similar issue:

Seems this issue is appears when chosen initialized before parent container is hidden.
I made simple code to reproduce the issue : https://jsfiddle.net/vdrs92rp/6/

Also according to (Mozilla https://developer.mozilla.org/docs/Web/API/HTMLElement/offsetWidth) this property is not working properly also with "position : fixed".

I see few workarounds:

  1. use hardcoded width in chosen js

  2. setting width of chosen js by js script after Chosen is inited (to override 0px)
    (for this we don't need to modify any code in chosen lib)

  3. use other methods to get width of select (jQuery width?) or at least use this method as failback when offsetWidth returned 0/null

@tjschuck
Copy link
Member

Pretty sure this is a duplicate of the long-standing #92. Please feel free to leave any additional feedback you have there. There's also a number of workarounds offered up on that issue.

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

No branches or pull requests

4 participants