Skip to content

Commit

Permalink
Show "title" when using a non-multiple select.
Browse files Browse the repository at this point in the history
A blank option is prepended to the select, which is then selected by
default. This allows the title to be shown when the select is initially
loaded and "no" options are selected yet. Close snapappointments#888. Close snapappointments#738.
  • Loading branch information
caseyjhol authored and avantika-gupta-jtg committed May 14, 2020
1 parent c2d38e7 commit 28372b5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
9 changes: 8 additions & 1 deletion dist/js/bootstrap-select.js
Expand Up @@ -387,7 +387,8 @@
createLi: function () {
var that = this,
_li = [],
optID = 0;
optID = 0,
titleOption = '<option class="bs-title-option" value="" selected></option>';

// Helper functions
/**
Expand Down Expand Up @@ -423,9 +424,15 @@
'</a>';
};

if (this.options.title && !this.multiple && !this.$element.find('.bs-title-option').length) {
this.$element.prepend(titleOption);
}

this.$element.find('option').each(function (index) {
var $this = $(this);

if ($this.hasClass('bs-title-option')) return;

// Get the class and text for the option
var optionClass = $this.attr('class') || '',
inline = $this.attr('style'),
Expand Down

0 comments on commit 28372b5

Please sign in to comment.