From 3369ec340d302ff37f1a8bb52d26a2d270c28596 Mon Sep 17 00:00:00 2001 From: Felix Nagel Date: Thu, 12 Jan 2012 22:01:49 +0100 Subject: [PATCH] Selectmenu: removed option value --- tests/unit/selectmenu/selectmenu_defaults.js | 1 - tests/unit/selectmenu/selectmenu_options.js | 10 ---- tests/visual/selectmenu/methods.html | 12 +++- tests/visual/selectmenu/option.html | 63 -------------------- ui/jquery.ui.selectmenu.js | 21 +++---- 5 files changed, 18 insertions(+), 89 deletions(-) delete mode 100644 tests/visual/selectmenu/option.html diff --git a/tests/unit/selectmenu/selectmenu_defaults.js b/tests/unit/selectmenu/selectmenu_defaults.js index a0f4f985e..9f6a1a964 100644 --- a/tests/unit/selectmenu/selectmenu_defaults.js +++ b/tests/unit/selectmenu/selectmenu_defaults.js @@ -8,7 +8,6 @@ commonWidgetTests( "selectmenu", { at: "left bottom", collision: "none" }, - value: null, // callbacks, create: null, open: null, diff --git a/tests/unit/selectmenu/selectmenu_options.js b/tests/unit/selectmenu/selectmenu_options.js index 913d1b4c9..9fd053673 100644 --- a/tests/unit/selectmenu/selectmenu_options.js +++ b/tests/unit/selectmenu/selectmenu_options.js @@ -33,14 +33,4 @@ ok(this.element.selectmenu("option", "dropdown", false), "accepts false"); }); - test("value option", function () { - expect(1); - - var value = this.element.find("option").eq(0).text(); - - this.element.selectmenu("option", "value", value); - - equals(this.element.selectmenu("option", "value"), value, "should be set to " + value); - }); - })(jQuery); diff --git a/tests/visual/selectmenu/methods.html b/tests/visual/selectmenu/methods.html index b3e5a42e5..3be5336bd 100644 --- a/tests/visual/selectmenu/methods.html +++ b/tests/visual/selectmenu/methods.html @@ -15,16 +15,23 @@ - - - - - - - - - - - - -
- -
-
- - -
-
-
- - - -
- - - - - diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js index 4b774e179..fbfd92bd0 100644 --- a/ui/jquery.ui.selectmenu.js +++ b/ui/jquery.ui.selectmenu.js @@ -27,7 +27,6 @@ $.widget( "ui.selectmenu", { at: "left bottom", collision: "none" }, - value: null, // callbacks open: null, focus: null, @@ -43,13 +42,6 @@ $.widget( "ui.selectmenu", { // array of button and menu id's this.ids = { id: selectmenuId, button: selectmenuId + '-button', menu: selectmenuId + '-menu' }; - // set current value - if ( this.options.value ) { - this.element[0].value = this.options.value; - } else { - this.options.value = this.element[0].value; - } - // catch click event of the label this._bind({ 'click': function( event ) { @@ -131,7 +123,7 @@ $.widget( "ui.selectmenu", { item = ui.item.data( "item.selectmenu" ), oldIndex = that.element[0].selectedIndex; - that._setOption( "value", item.value ); + that._setIndex( item.index ); that._trigger( "select", event, { item: item } ); if ( item.index != oldIndex ) { @@ -173,6 +165,8 @@ $.widget( "ui.selectmenu", { this._renderMenu( this.menu, this.items ); this.menu.menu( "refresh" ); + // button option label wont work here + this.button.children( '.ui-button-text' ).text( this.items[ this.element[0].selectedIndex ].label ); // adjust ARIA this.menu.find( "li" ).not( '.ui-selectmenu-optgroup' ).find( 'a' ).attr( 'role', 'option' ); @@ -386,6 +380,11 @@ $.widget( "ui.selectmenu", { } } }, + + _setIndex: function( index ) { + this.element[0].selectedIndex = index; + this.button.button( "option", "label", this.items[ index ].label ); + }, _setOption: function( key, value ) { this._super( key, value ); @@ -393,10 +392,6 @@ $.widget( "ui.selectmenu", { if ( key === "appendTo" ) { this.menuWrap.appendTo( $( value || "body", this.element[0].ownerDocument )[0] ); } - if ( key === "value" && value !== undefined ) { - this.element[0].value = value; - this.button.children( '.ui-button-text' ).text( this.items[ this.element[0].selectedIndex ].label ); - } if ( key === "disabled" ) { this.button.button( "option", "disabled", value ); this.menu.menu( "option", "disabled", value );