setTimeout( function() {
button.trigger( "click" );
options = menu.children()
- .map( function() {
- return $( this ).text();
+ .get()
+ .filter( function( item ) {
+ return $( item ).is( ":visible" );
} )
- .get();
+ .map( function( item ) {
+ return $( item ).text();
+ } );
assert.deepEqual( options, [ "Slower", "Medium", "Fast", "Faster" ], "correct elements" );
ready();
} );
} );
+QUnit.test( "Options with hidden attribute should not break the widget (gh-2082)",
+ function( assert ) {
+ var ready = assert.async();
+ assert.expect( 1 );
+
+ var button;
+ var element = $( "#speed" );
+
+ element.find( "option" ).slice( 0, 2 ).prop( "hidden", true );
+ element.val( "Faster" );
+ element.selectmenu();
+
+ button = element.selectmenu( "widget" );
+ button.simulate( "focus" );
+ setTimeout( function() {
+ try {
+ button.trigger( "click" );
+ assert.strictEqual( button.text(), "Faster", "Selected value is correct" );
+ } catch ( e ) {
+ assert.ok( false, "Clicking on the select box crashed" );
+ }
+
+ ready();
+ } );
+} );
+
+QUnit.test( "Optgroups with hidden attribute should not break the widget (gh-2082)",
+ function( assert ) {
+ var ready = assert.async();
+ assert.expect( 1 );
+
+ var button;
+ var element = $( "#files" );
+
+ element.find( "optgroup" ).first().prop( "hidden", true );
+ element
+ .find( "optgroup" ).eq( 1 )
+ .find( "option" ).first()
+ .prop( "hidden", true );
+ element.val( "someotherfile" );
+ element.selectmenu();
+
+ button = element.selectmenu( "widget" );
+ button.simulate( "focus" );
+ setTimeout( function() {
+ try {
+ button.trigger( "click" );
+ assert.strictEqual( button.text(), "Some other file", "Selected option is correct" );
+ } catch ( e ) {
+ assert.ok( false, "Clicking on the select box crashed" );
+ }
+
+ ready();
+ } );
+} );
+
QUnit.test( "extra listeners created after selection (trac-15078, trac-15152)", function( assert ) {
assert.expect( 3 );
if ( item.disabled ) {
this._addClass( li, null, "ui-state-disabled" );
}
- this._setText( wrapper, item.label );
+
+ if ( item.hidden ) {
+ li.prop( "hidden", true );
+ } else {
+ this._setText( wrapper, item.label );
+ }
return li.append( wrapper ).appendTo( ul );
},
var that = this,
data = [];
options.each( function( index, item ) {
- if ( item.hidden ) {
- return;
- }
-
data.push( that._parseOption( $( item ), index ) );
} );
this.items = data;
index: index,
value: option.val(),
label: option.text(),
+ hidden: optgroup.prop( "hidden" ) || option.prop( "hidden" ),
optgroup: optgroup.attr( "label" ) || "",
disabled: optgroup.prop( "disabled" ) || option.prop( "disabled" )
};