Sha256: 71ff1b520edab940a88f7d1bfc46193b517c516e745863a43844b61c27ddbaa3
Contents?: true
Size: 1.14 KB
Versions: 12
Compression:
Stored size: 1.14 KB
Contents
document.addEventListener('DOMContentLoaded', function() { // Initiate a standard Select2 on any select element with the class .select2 // Remember to add a place holder in the HTML as needed. $('select.select2').select2({}) // Initiate a Select2 with the option to clear, on any select element with the class .select2-clear // Set: include_blank: true in the ERB. // A placeholder is auto-added here as it is required to clear the Select2. $('select.select2-clear').select2({ placeholder: Spree.translations.select_an_option, allowClear: true }) }) $.fn.addSelect2Options = function (data) { var select = this function appendOption(select, data) { var option = new Option(data.name, data.id, true, true) select.append(option).trigger('change') } if (Array.isArray(data)) { data.map(function(row) { appendOption(select, row) }) } else { appendOption(select, data) } select.trigger({ type: 'select2:select', params: { data: data } }) } $.fn.select2.defaults.set('width', 'style') $.fn.select2.defaults.set('dropdownAutoWidth', false) $.fn.select2.defaults.set('theme', 'bootstrap4')
Version data entries
12 entries across 12 versions & 1 rubygems