Sha256: 59f6a35acc0e4e8e81e235e2f619fb2c47333ab4471a108bb482ca8101c65273

Contents?: true

Size: 1.28 KB

Versions: 10

Compression:

Stored size: 1.28 KB

Contents

$(function() {
  configureSelect2(document);

  $(document).on('has_many_add:after', function(event, container) {
    configureSelect2(container);
  });

  function configureSelect2(container) {
    if (ActiveadminAddons.config.defaultSelect == 'select2') {
      $('select:not(.default-select)', container).each(function(i, el) {
        setupSelect2(el);
      });
    }

    $('select.select2', container).each(function(i, el) {
      setupSelect2(el);
    });

    function setupSelect2(select) {
      var selectConfig = {
        placeholder: '',
        width: '80%',
        allowClear: true,
      };

      function isFilter(path) {
        return $(select).closest(path).length > 0;
      }

      if (isFilter('.select_and_search')) {
        selectConfig.width = 'resolve';
        selectConfig.allowClear = false;
      } else if (isFilter('.filter_select')) {
        selectConfig.width = 'resolve';
      }

      $(select).select2(selectConfig);

      // Related with https://github.com/select2/select2/issues/3320
      $(select).on('select2:unselecting', function() {
        $(this).data('unselecting', true);
      }).on('select2:open', function() {
        if ($(this).data('unselecting')) {
          $(this).select2('close').removeData('unselecting');
        }
      });
    }
  }
});

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
activeadmin_addons-1.6.0 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.5.0 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.4.0 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.3.0 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.2.0 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.1.2 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.1.1 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.1.0 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.0.1 app/assets/javascripts/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.0.0 app/assets/javascripts/activeadmin_addons/inputs/select2.js