Sha256: 59752ad99b6a34ff3fe9f8bf28cdc8e83a4484c2908dd0ef604c1894a9207d02
Contents?: true
Size: 1.19 KB
Versions: 12
Compression:
Stored size: 1.19 KB
Contents
(function() { function initSearchableSelects(inputs, extra) { inputs.each(function() { var item = $(this); // reading from data allows <input data-searchable_select='{"tags": ['some']}'> // to be passed to select2 var options = $.extend(extra || {}, item.data('searchableSelect')); var url = item.data('ajaxUrl'); if (url) { $.extend(options, { ajax: { url: url, dataType: 'json', data: function (params) { return { term: params.term, page: pageParamWithBaseZero(params) }; } } }); } item.select2(options); }); } function pageParamWithBaseZero(params) { return params.page ? params.page - 1 : undefined; } $(document).on('has_many_add:after', '.has_many_container', function(e, fieldset) { initSearchableSelects(fieldset.find('.searchable-select-input')); }); $(document).on('page:load turbolinks:load', function() { initSearchableSelects($(".searchable-select-input"), {placeholder: ""}); }); $(function() { initSearchableSelects($(".searchable-select-input")); }); }());
Version data entries
12 entries across 11 versions & 1 rubygems