Selectmenu: removed option value

This commit is contained in:
Felix Nagel 2012-01-12 22:01:49 +01:00
parent 38eaad39cf
commit 3369ec340d
5 changed files with 18 additions and 89 deletions

View File

@ -8,7 +8,6 @@ commonWidgetTests( "selectmenu", {
at: "left bottom",
collision: "none"
},
value: null,
// callbacks,
create: null,
open: null,

View File

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

View File

@ -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>

View File

@ -1,63 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Selectmenu - Option functionality</title>
<link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css">
<script src="../../../jquery-1.7.1.js"></script>
<script src="../../../ui/jquery.ui.core.js"></script>
<script src="../../../ui/jquery.ui.widget.js"></script>
<script src="../../../ui/jquery.ui.position.js"></script>
<script src="../../../ui/jquery.ui.button.js"></script>
<script src="../../../ui/jquery.ui.menu.js"></script>
<script src="../../../ui/jquery.ui.selectmenu.js"></script>
<link rel="stylesheet" href="../../../demos/demos.css">
<script>
$(function() {
var mySelectmenu = $('select').selectmenu();
$("#value").click( function() {
mySelectmenu.selectmenu("option", "value", "Faster");
});
$("#dropdown").toggle( function() {
mySelectmenu.selectmenu("option", "dropdown", false);
}, function() {
mySelectmenu.selectmenu("option", "dropdown", true);
});
});
</script>
<style>
form { margin: 20px 0 0 0 }
fieldset { border: 0; }
label { display: block; }
select { width: 200px; }
.overflow ul { height: 200px; overflow: auto; }
</style>
</head>
<body>
<div class="demo">
<form action="#">
<fieldset>
<label for="speed">Select a speed:</label>
<select name="speed" id="speed">
<option value="Slower">Slower</option>
<option value="Slow">Slow</option>
<option value="Medium" selected="selected">Medium</option>
<option value="Fast">Fast</option>
<option value="Faster">Faster</option>
</select>
</fieldset>
</form>
<br />
<!-- <button id="dropdown">Toggle dropdown style</button> -->
<button id="value">Set option value = 'Faster'</button>
</div><!-- End demo -->
</body>
</html>

View File

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