Created
November 28, 2017 10:46
-
-
Save dmarchuk/53c480e1e1ba7339cbb8d0fe19d9375d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Override default 'renderItems()' function of selectivity | |
* to accept option with value='' (empty string, item.id === '') as a valid option. | |
* | |
* @param items Array of result items. | |
* @returns HTML-formatted string to display the result items. | |
*/ | |
$.Selectivity.Dropdown.prototype.renderItems = function (items) { | |
const selectivity = this.selectivity; | |
const originalEl = selectivity.options.element; | |
const $optionElements = $(originalEl.options); | |
const hasClass = $(originalEl).find('[data-class]').length; | |
return items.map(function (item) { | |
if (hasClass) { | |
$optionElements.each(function (i, el) { | |
const $el = $(el); | |
const id = $el.val(); | |
if (id == item.id) { | |
item.cssClass = $(el).data('class'); | |
return false | |
} | |
}); | |
} | |
let result = selectivity.template(item.id === '' || item.id ? 'resultItem' : 'resultLabel', item); | |
if (item.children) { | |
result += selectivity.template('resultChildren', { | |
childrenHtml: this.renderItems(item.children), | |
}); | |
} | |
return result; | |
}, this).join(''); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment