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

Version Path
activeadmin-searchable_select-1.8.0 src/searchable_select/init.js
activeadmin-searchable_select-1.8.0 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.7.0 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.6.0 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.5.0 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.4.0 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.3.0 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.2.1 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.2.0 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.1.0 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.0.2 app/assets/javascripts/active_admin/searchable_select/init.js
activeadmin-searchable_select-1.0.1 app/assets/javascripts/active_admin/searchable_select/init.js