Skip to content
Permalink
Browse files

Selectmenu: removed option value

  • Loading branch information...
fnagel committed Jan 12, 2012
1 parent 38eaad3 commit 3369ec340d302ff37f1a8bb52d26a2d270c28596
@@ -8,7 +8,6 @@ commonWidgetTests( "selectmenu", {
at: "left bottom",
collision: "none"
},
value: null,
// callbacks,
create: null,
open: null,
@@ -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);
@@ -15,16 +15,23 @@
<script>
$(function() {
var mySelectmenu = $('select').selectmenu();
$('select').show();
$("#destroy").click( function() {
mySelectmenu.selectmenu("destroy");
});
$("#refresh").click( function() {
$("#refresh_add").click( function() {
mySelectmenu.append('<option value="fastsound">Faster than sound</option>');
mySelectmenu.selectmenu("refresh");
});
$("#refresh_selected").click( function() {
mySelectmenu[0].selectedIndex = 0;
mySelectmenu.selectmenu("refresh");
});
$("#open").click( function() {
mySelectmenu.selectmenu("open");
return false;
@@ -62,7 +69,8 @@
</form>
<br />
<button id="destroy">Destroy</button>
<button id="refresh">Add item and refresh</button>
<button id="refresh_add">Add item and refresh</button>
<button id="refresh_selected">Change to first item</button>
<button id="open">Open</button>
<button id="close">Close</button>

This file was deleted.

@@ -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,17 +380,18 @@ $.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 );

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 );

0 comments on commit 3369ec3

Please sign in to comment.
You can’t perform that action at this time.