From b3dc2709270f2a8106d03dddd6e0d8dd143429fb Mon Sep 17 00:00:00 2001 From: jannnci Date: Wed, 22 Oct 2014 16:26:27 +0200 Subject: [PATCH 1/5] call refresh(): this.menuItems was undefined Calling refresh() on selectmenu without an option throw error: "this.menuItems is undefined" Now i create this.menuItems also for selectmenu without option and in open function i check if this.menuItems realy has an item. Fixes #10662 --- ui/selectmenu.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/ui/selectmenu.js b/ui/selectmenu.js index 26456b0dc1b..9582953cb1d 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 { From 3a8007dd4cde05f7ef79b5ea750545a3fea8c9ff Mon Sep 17 00:00:00 2001 From: jannnci Date: Wed, 22 Oct 2014 21:20:11 +0200 Subject: [PATCH 2/5] correction == vs === --- ui/selectmenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/selectmenu.js b/ui/selectmenu.js index 9582953cb1d..722c97c2480 100644 --- a/ui/selectmenu.js +++ b/ui/selectmenu.js @@ -230,7 +230,7 @@ return $.widget( "ui.selectmenu", { } // If this is the first time the menu is being opened, render the items - if ( !this.menuItems || this.menuItems.length==0) { + if ( !this.menuItems || this.menuItems.length===0) { this._refreshMenu(); } else { From 5ddc45c6cffc0a66029fb73bef74ea58d4181f4f Mon Sep 17 00:00:00 2001 From: jannnci Date: Wed, 22 Oct 2014 21:32:01 +0200 Subject: [PATCH 3/5] correction === --- ui/selectmenu.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/selectmenu.js b/ui/selectmenu.js index 722c97c2480..cabbeefb935 100644 --- a/ui/selectmenu.js +++ b/ui/selectmenu.js @@ -230,7 +230,7 @@ return $.widget( "ui.selectmenu", { } // If this is the first time the menu is being opened, render the items - if ( !this.menuItems || this.menuItems.length===0) { + if ( !this.menuItems || this.menuItems.length === 0 ) { this._refreshMenu(); } else { From be93bd727b4f33a49a1db43209f55286a26c5296 Mon Sep 17 00:00:00 2001 From: jannnci Date: Mon, 27 Oct 2014 18:08:00 +0100 Subject: [PATCH 4/5] added select without an option --- tests/unit/selectmenu/selectmenu.html | 4 ++++ 1 file changed, 4 insertions(+) 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 @@ + + + From 7840ea94d9a6d195670e9bbcd731333223d58d0b Mon Sep 17 00:00:00 2001 From: Jan Malac Date: Tue, 28 Oct 2014 10:56:35 +0100 Subject: [PATCH 5/5] added refresh tests for selectmenu without options --- tests/unit/selectmenu/selectmenu_methods.js | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) 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 );