Permalink
Browse files

Selectmenu: removed option value

  • Loading branch information...
1 parent 38eaad3 commit 3369ec340d302ff37f1a8bb52d26a2d270c28596 @fnagel fnagel committed Jan 12, 2012
@@ -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>
@@ -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
@@ -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.