-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Use the better supported offsetWidth property to get a fields width #1172
Conversation
Firefox does not return the correct value for |
@pfiller The code looks good. Could you give me an example of how to make the issue happen in master? I'm trying to browser test it really quick. |
You're right - #202 is the one that would be closed. In master, just view the example page in Chrome and then Firefox. Note the difference in field widths. Sloppy 😦 |
Conflicts: chosen/chosen.jquery.min.js chosen/chosen.proto.min.js
Use the better supported offsetWidth property to get a fields width
offsetWidth returns 0 if the element is hidden. --- chosen.jquery.js.orig 2013-06-05 14:29:10.125064465 +0000 +++ chosen.jquery.js 2013-06-05 14:23:24.868646488 +0000 @@ -318,6 +318,9 @@ if (this.options.width != null) { return this.options.width; } else { + if (this.form_field.offsetWidth == 0) { + return "" + $(this.form_field).width() + "px"; + } return "" + this.form_field.offsetWidth + "px"; } }; |
If the field is hidden, the best workaround is to tell Chosen what width to use explicitly: $("select").chosen({ width: 'some-width' }); |
but if the parent element is hidden (in case of jquery.modal() is closed and reopened), the field is not available in offsetWidth. only return width if use $(this.form_field).width() sorry my english |
Pfiller, in that case you cannot specify the width using css. |
Fixes #202