diff --git a/tests/unit/selectmenu/selectmenu.html b/tests/unit/selectmenu/selectmenu.html index 618eea3d00a..09ffbd9ae10 100644 --- a/tests/unit/selectmenu/selectmenu.html +++ b/tests/unit/selectmenu/selectmenu.html @@ -82,6 +82,10 @@ + + + diff --git a/tests/unit/selectmenu/selectmenu_methods.js b/tests/unit/selectmenu/selectmenu_methods.js index ca1b8c6a34c..326a6e6b177 100644 --- a/tests/unit/selectmenu/selectmenu_methods.js +++ b/tests/unit/selectmenu/selectmenu_methods.js @@ -154,6 +154,39 @@ test( "refresh - disabled optgroup", function() { } }); +test( "refresh - empty select", function() { + expect( 1 ); + + var element = $( "#emptySelect" ).selectmenu(); + try{ + element.selectmenu( "refresh" ); + ok( true, "refresh empty select without error" ); + }catch(err) { + ok( false, err.message ); + } +}); + +test( "refresh - structure remove all options", function() { + expect( 4 ); + + var element = $( "#speed" ).selectmenu(), + menu = element.selectmenu( "menuWidget" ), + options = element.find( "option" ), + menuItems = menu.find( "li" ).not( ".ui-selectmenu-optgroup" ); + // refresh select with some options + element.selectmenu( "refresh" ); + ok( true, "first refresh ok" ); + // remove all options and refresh + element.children().remove(); + element.selectmenu( "refresh" ); + ok( true, "refresh empty select ok" ); + //check length for option and menuItems is 0 + options = element.find( "option" ); + menuItems = menu.find( "li" ).not( ".ui-selectmenu-optgroup" ); + equal( options.length, 0, "options length" ); + equal( menuItems.length, 0, "menu item length" ); +}); + test( "widget and menuWidget", function() { expect( 4 ); diff --git a/ui/selectmenu.js b/ui/selectmenu.js index 26456b0dc1b..cabbeefb935 100644 --- a/ui/selectmenu.js +++ b/ui/selectmenu.js @@ -203,15 +203,16 @@ return $.widget( "ui.selectmenu", { var item, options = this.element.find( "option" ); + this._parseOptions( options ); + this._renderMenu( this.menu, this.items ); + + this.menuItems = this.menu.find( "li" ).not( ".ui-selectmenu-optgroup" ); + if ( !options.length ) { return; } - this._parseOptions( options ); - this._renderMenu( this.menu, this.items ); - this.menuInstance.refresh(); - this.menuItems = this.menu.find( "li" ).not( ".ui-selectmenu-optgroup" ); item = this._getSelectedItem(); @@ -229,7 +230,7 @@ return $.widget( "ui.selectmenu", { } // If this is the first time the menu is being opened, render the items - if ( !this.menuItems ) { + if ( !this.menuItems || this.menuItems.length === 0 ) { this._refreshMenu(); } else {