Skip to content

Commit 68d3b1e

Browse files
committed
Fixed bug where controls without any options would render with incorrect heights
1 parent 56b3969 commit 68d3b1e

File tree

3 files changed

+43
-31
lines changed

3 files changed

+43
-31
lines changed

index.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@
166166
</select>
167167
</p>
168168

169+
<p>
170+
Empty Dropdown<br />
171+
<select name="empty-dropdown"></select>
172+
</p>
173+
169174
<p>
170175
Multi-select Control<br />
171176
<select name="multi-select-control" multiple="multiple">
@@ -177,6 +182,11 @@
177182
</select>
178183
</p>
179184

185+
<p>
186+
Empty Multi-select<br />
187+
<select name="empty-multi-select" size="5" multiple="multiple"></select>
188+
</p>
189+
180190
<p>
181191
No multi-select, size = 4<br />
182192
<select name="no-multi-with-size-4" size="4">

jquery.selectBox.js

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
3-
jQuery selectBox (version 1.0.3)
3+
jQuery selectBox (version 1.0.4)
44
55
A cosmetic, styleable replacement for SELECT elements.
66
@@ -87,6 +87,7 @@
8787
for setting the width
8888
- Added 'control' method for working directly with the selectBox control
8989
v1.0.3 (2011-04-22) - Fixed bug in value method that errored if the control didn't exist
90+
v1.0.4 (2011-04-22) - Fixed bug where controls without any options would render with incorrect heights
9091
9192
9293
Known Issues:
@@ -169,24 +170,21 @@ if(jQuery) (function($) {
169170
// Auto-height based on size attribute
170171
if( !select[0].style.height ) {
171172

172-
var size = select.attr('size') ? parseInt(select.attr('size')) : 5,
173-
optionHeight = parseInt(control.find('.selectBox-options A:first').outerHeight());
174-
175-
// If the control is invisible, we have to draw a dummy control
176-
// off-screen, measure the option, and remove it
177-
if( !select.is(':visible') ) {
178-
var tmp = control
179-
.clone()
180-
.removeAttr('id')
181-
.css({
182-
position: 'absolute',
183-
top: '-9999em'
184-
})
185-
.show()
186-
.appendTo('body');
187-
optionHeight = parseInt(tmp.find('.selectBox-options A:first').html('&nbsp;').outerHeight());
188-
tmp.remove();
189-
}
173+
var size = select.attr('size') ? parseInt(select.attr('size')) : 5;
174+
175+
// Draw a dummy control off-screen, measure, and remove it
176+
var tmp = control
177+
.clone()
178+
.removeAttr('id')
179+
.css({
180+
position: 'absolute',
181+
top: '-9999em'
182+
})
183+
.show()
184+
.appendTo('body');
185+
tmp.find('.selectBox-options').html('<li><a>\u00A0</a></li>');
186+
optionHeight = parseInt(tmp.find('.selectBox-options A:first').html('&nbsp;').outerHeight());
187+
tmp.remove();
190188

191189
control.height(optionHeight * size);
192190

@@ -343,16 +341,20 @@ if(jQuery) (function($) {
343341

344342
} else {
345343

346-
select.find('OPTION').each( function() {
347-
var li = $('<li />'),
348-
a = $('<a />');
349-
li.addClass( $(this).attr('class') );
350-
a.attr('rel', $(this).val()).text( $(this).text() );
351-
li.append(a);
352-
if( $(this).attr('disabled') ) li.addClass('selectBox-disabled');
353-
if( $(this).attr('selected') ) li.addClass('selectBox-selected');
354-
options.append(li);
355-
});
344+
if( select.find('OPTION').length > 0 ) {
345+
select.find('OPTION').each( function() {
346+
var li = $('<li />'),
347+
a = $('<a />');
348+
li.addClass( $(this).attr('class') );
349+
a.attr('rel', $(this).val()).text( $(this).text() );
350+
li.append(a);
351+
if( $(this).attr('disabled') ) li.addClass('selectBox-disabled');
352+
if( $(this).attr('selected') ) li.addClass('selectBox-selected');
353+
options.append(li);
354+
});
355+
} else {
356+
options.append('<li>\u00A0</li>');
357+
}
356358

357359
}
358360

0 commit comments

Comments
 (0)