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

Commit

Permalink
[custom select] Filter placeholders out of the list of selected items -
Browse files Browse the repository at this point in the history
Fixes: #4061
  • Loading branch information
Gabriel Schulhof committed Jun 21, 2012
1 parent 4707068 commit fd959b9
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions js/jquery.mobile.forms.select.custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,22 @@ define( [
return options.text() !== list.text();
},

selected: function() {
return this._selectOptions().filter( ":selected:not(:jqmData(placeholder='true'))" );
},

refresh: function( forceRebuild , foo ){
var self = this,
select = this.element,
isMultiple = this.isMultiple,
options = this._selectOptions(),
selected = this.selected(),
// return an array of all selected index's
indicies = this.selectedIndices();
indices;

if ( forceRebuild || this._isRebuildRequired() ) {
self._buildList();
}

indicies = this.selectedIndices();

self.setButtonText();
self.setButtonCount();

Expand Down Expand Up @@ -461,6 +464,7 @@ define( [
dataIndexAttr = dataPrefix + 'option-index',
dataIconAttr = dataPrefix + 'icon',
dataRoleAttr = dataPrefix + 'role',
dataPlaceholderAttr = dataPrefix + 'placeholder',
fragment = document.createDocumentFragment(),
isPlaceholderItem = false,
optGroup;
Expand Down Expand Up @@ -493,6 +497,9 @@ define( [
if (needPlaceholder && (!option.getAttribute( "value" ) || text.length == 0 || $option.jqmData( "placeholder" ))) {
needPlaceholder = false;
isPlaceholderItem = true;

// If we have identified a placeholder, mark it retroactively in the select as well
option.setAttribute( dataPlaceholderAttr, true );
if ( o.hidePlaceholderMenuItems ) {
classes.push( "ui-selectmenu-placeholder" );
}
Expand All @@ -509,7 +516,7 @@ define( [
item.setAttribute(dataIndexAttr,i);
item.setAttribute(dataIconAttr,dataIcon);
if ( isPlaceholderItem ) {
item.setAttribute( dataPrefix + "placeholder", true );
item.setAttribute( dataPlaceholderAttr, true );
}
item.className = classes.join(" ");
item.setAttribute('role','option');
Expand Down

0 comments on commit fd959b9

Please sign in to comment.