Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
create selectOptions method so the values stay current across dom cha…
Browse files Browse the repository at this point in the history
…nges Fixes #2410
  • Loading branch information
johnbender committed Sep 9, 2011
1 parent 0b83cf8 commit 729757b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions js/jquery.mobile.forms.select.custom.js
Expand Up @@ -13,7 +13,7 @@
label = widget.label,
thisPage = widget.select.closest( ".ui-page" ),
screen = $( "<div>", {"class": "ui-selectmenu-screen ui-screen-hidden"} ).appendTo( thisPage ),
selectOptions = widget.select.find("option"),
selectOptions = widget._selectOptions(),
isMultiple = widget.isMultiple = widget.select[ 0 ].multiple,
buttonId = selectID + "-button",
menuId = selectID + "-menu",
Expand Down Expand Up @@ -108,7 +108,7 @@
// index of option tag to be selected
var oldIndex = self.select[ 0 ].selectedIndex,
newIndex = self.list.find( "li:not(.ui-li-divider)" ).index( this ),
option = self.selectOptions.eq( newIndex )[ 0 ];
option = self._selectOptions().eq( newIndex )[ 0 ];

// toggle selected status on the tag for multi selects
option.selected = self.isMultiple ? !option.selected : true;
Expand Down Expand Up @@ -206,7 +206,7 @@
var self = this,
select = this.element,
isMultiple = this.isMultiple,
options = this.selectOptions = select.find( "option" ),
options = this._selectOptions(),
selected = this.selected(),
// return an array of all selected index's
indicies = this.selectedIndices();
Expand Down
9 changes: 6 additions & 3 deletions js/jquery.mobile.forms.select.js
Expand Up @@ -55,14 +55,17 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
}, 40);
},

_selectOptions: function() {
return this.select.find( "option" );
},

// setup items that are generally necessary for select menu extension
_preExtension: function(){
this.select = this.element.wrap( "<div class='ui-select'>" );
this.selectID = this.select.attr( "id" );
this.label = $( "label[for='"+ this.selectID +"']" ).addClass( "ui-select" );
this.isMultiple = this.select[ 0 ].multiple;
this.options.theme = this._theme();
this.selectOptions = this.select.find( "option" );
},

_create: function() {
Expand Down Expand Up @@ -153,14 +156,14 @@ $.widget( "mobile.selectmenu", $.mobile.widget, {
},

selected: function() {
return this.selectOptions.filter( ":selected" );
return this._selectOptions().filter( ":selected" );
},

selectedIndices: function() {
var self = this;

return this.selected().map( function() {
return self.selectOptions.index( this );
return self._selectOptions().index( this );
}).get();
},

Expand Down

0 comments on commit 729757b

Please sign in to comment.