Skip to content

Commit

Permalink
added placeholder attribute support for compact multiple selects
Browse files Browse the repository at this point in the history
  • Loading branch information
inferpse committed May 27, 2015
1 parent 39a39be commit 34f785c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
3 changes: 1 addition & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,7 @@ <h2>&lt;select&gt;</h2>
<option>Option 22</option>
<option>Option 23</option>
</select>
<select multiple data-jcf='{"wrapNative": false, "wrapNativeOnMobile": false, "useCustomScroll": false, "multipleCompactStyle": true}'>
<option selected value="v1">Compact multiple select</option>
<select multiple placeholder="Compact multiple select" data-jcf='{"wrapNative": false, "wrapNativeOnMobile": false, "useCustomScroll": false, "multipleCompactStyle": true}'>
<option value="v2">Option 1</option>
<option value="v3">Option 2</option>
<option value="v4">Option 3</option>
Expand Down
6 changes: 5 additions & 1 deletion js/jcf.select.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,14 +388,18 @@
selectedOption = this.realElement.prop('options')[selectedIndex],
selectedOptionImage = selectedOption ? selectedOption.getAttribute('data-image') : null,
selectedOptionText = '',
selectedOptionClasses;
selectedOptionClasses,
self = this;

if (this.realElement.prop('multiple')) {
$.each(this.realElement.prop('options'), function(index, option) {
if (option.selected) {
selectedOptionText += (selectedOptionText ? ', ' : '') + option.innerHTML;
}
});
if (!selectedOptionText) {
selectedOptionText = self.realElement.attr('placeholder') || '';
}
this.selectText.removeAttr('class').html(selectedOptionText);
} else if (!selectedOption) {
if (this.selectImage) {
Expand Down

0 comments on commit 34f785c

Please sign in to comment.