Sha256: b8f630cc02a66037faf747e5df770aaf8dc3f1dc2504166c54c73342fb7e3e9a

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

var initializer = function() {
  configureSelect2(document);

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

  function configureSelect2(container) {
    if (window.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');
        }
      });
    }
  }
};

$(initializer);
$(document).on('turbolinks:load', initializer);

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
activeadmin_addons-1.9.0 app/javascript/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.8.3 app/javascript/activeadmin_addons/inputs/select2.js
activeadmin_addons-1.8.2 app/javascript/activeadmin_addons/inputs/select2.js
activeadmin_addons_rails6-1.7.2 app/javascript/activeadmin_addons/inputs/select2.js