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

size and data-size not always working #31

Closed
dfliess opened this issue Dec 30, 2012 · 12 comments
Closed

size and data-size not always working #31

dfliess opened this issue Dec 30, 2012 · 12 comments

Comments

@dfliess
Copy link

dfliess commented Dec 30, 2012

I Think that the size option stopped working for element's that have not been attached to the DOM.

For what I've seen without knowing the full code the issue could be in line 31

var liHeight = parseInt(menuA.css('line-height')) + menuA.outerHeight(); //NaN

.css('line-height') is "".

At least on Chrome v23.0.1271.101:

$('').css('line-height')

I've patched by the moment with a default value like this:

var liHeight = parseInt(menuA.css('line-height'),10)||25 + menuA.outerHeight();

I know it's not the perfect solution....but not sure how to fix it.

@silviomoreto
Copy link
Collaborator

Have you tried to apply seletpicker after changing your DOM?

try execute $('.selectpicker').selectpicker(); again

@dfliess
Copy link
Author

dfliess commented Jan 24, 2013

I wish I can do that but I'm using this at a Backbone.View on the render method and kind of calling .selectpicker inside the method, and the element is added to the DOM later, not by the View itself.

@kayzee
Copy link

kayzee commented Mar 21, 2013

Confirmed that executing this again does not fix the size issue.
$('.selectpicker').selectpicker();

@kayzee
Copy link

kayzee commented Mar 21, 2013

Also confirmed that commit 1c22c037178756ac894035bbbf2973887560e71a does not fix the size refresh problem.

@kayzee
Copy link

kayzee commented Mar 27, 2013

Don't mean to be a pest, but any plans on fixing this bug?

@mattbryson
Copy link
Contributor

Just looking at this for first time...

menuA.css('line-height') will return the CSS value of the element.

This is both browser and setting dependent, so it could be 25, '25px', or '' or 'normal'.

An empty string, or 'normal' will NOT parse to int with parseInt, you will get NaN.

So if you dont set the line-height to a int value, and you set data-size or data you will see this issue.

Can we not just use .height(); ?

@mattbryson
Copy link
Contributor

In fact, why does it need the combination of line-height and outerHeight() ?

Can it not just use outerHeight(true) - true to include margins.

knocked a fiddle showing the issues: http://jsfiddle.net/Msyym/

m.

@caseyjhol
Copy link
Member

That works if the menu is already displayed, but liHeight is calculated when the select is first created (while the menu is hidden), meaning outerHeight(true) doesn't work (returns a value of 6, when the value should be 26). This shouldn't really be an issue, as the line-height is set to 20px in the Bootstrap CSS, so it should never return NaN. Regardless, that whole feature probably needs a revamp, as I haven't really looked at it since I first introduced it at the beginning of December. I'll take a second look to figure out a better implementation.

caseyjhol added a commit that referenced this issue Mar 30, 2013
@caseyjhol
Copy link
Member

While I think size probably needs to be readdressed at some point, this seems to get the job done for now.

@kayzee
Copy link

kayzee commented Mar 31, 2013

Hey @caseyjhol, the most recent changes still don't solve my problem. Maybe it is different than what @dfliess described above. I set size to 10 and with 10 options present, I add an 11th element with the following:

$("#select_list option[value='']").after("<option value='#{value}' class='local'>#{value}</option>")
$("#select_list").selectpicker('reloadLi')  # reload the list (IE8 support)

I know that the size only gets calculated in the init method. Can you think of a clean way to "refresh" the control after adding/removing a new element? (Maybe moving the size calculation code into its own method that can be called from the refresh or reloadLi methods?)

@mattbryson
Copy link
Contributor

HI @kayzee,

Yeah, we could extract the size logic into its own function, and then call that on both init and a new method that forces a complete re build, such as refresh, as suggested in #52

m

@MikeMazz23
Copy link

So there are 2 common practices to make bootstrap type dropdowns. First is to use a select and the second is to a ul and li options (data toggle and dropdown-menu). When you use the select version, the first time the dropdown is expanded a ul is created with all li options having the values from the select options tags. There are now 2 lists in your page DOM. The ul li list and the original select. When you continue to play with the dropdown you will see the li class gets "selected" added to the option you picked, however the original select remains unchanged. The chrome dev tools shows this nicely by highlighting what has changed. This is probably why the size doesn't take effect immediately, bc it has to create the ul li list first. Why not does init? who knows..
This is unfortunate bc now we cannot use this great plugin with selects, only ul lists.
I know this issue was closed a long time ago, but maybe this will shed some light on the issue and help someone find a solution.

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

6 participants