How to use the select2/utils.Decorate function in select2

To help you get started, we’ve selected a few select2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github select2 / select2 / tests / selection / search-tests.js View on Github external
test('the focus event shifts the focus', function (assert) {
  // Check for IE 8, which triggers a false negative during testing
  if (window.attachEvent && !window.addEventListener) {
    // We must expect 0 assertions or the test will fail
    assert.expect(0);
    return;
  }

  var $container = $('#qunit-fixture .event-container');
  var container = new MockContainer();

  var CustomSelection = Utils.Decorate(MultipleSelection, InlineSearch);

  var $element = $('#qunit-fixture .multiple');
  var selection = new CustomSelection($element, options);

  var $selection = selection.render();
  selection.bind(container, $container);

  // Update the selection so the search is rendered
  selection.update([]);

  // Make it visible so the browser can place focus on the search
  $container.append($selection);

  // The search should not be automatically focused

  var $search = $selection.find('input');
github select2 / select2 / tests / results / infiniteScroll-tests.js View on Github external
assert.expect(1);

  var $ = require('jquery');

  var $select = $('<select></select>');

  var $container = $('<span></span>');
  var container = new MockContainer();

  var Utils = require('select2/utils');
  var Options = require('select2/options');

  var Results = require('select2/results');
  var InfiniteScroll = require('select2/dropdown/infiniteScroll');

  var InfiniteScrollResults = Utils.Decorate(Results, InfiniteScroll);

  var results = new InfiniteScrollResults($select, new Options({}));

  // Fake the data adapter for the `setClasses` method
  results.data = {};
  results.data.current = function (callback) {
    callback([{ id: 'test' }]);
  };

  $('#qunit-fixture').append(results.render());

  results.bind(container, $container);

  results.on('query:append', function () {
    assert.ok(true, 'It tried to load more immediately');
  });
github select2 / select2 / tests / selection / allowClear-tests.js View on Github external
test('clear button doesnt visually break selected options', function (assert) {
  var $element = $('<select></select>');

  var Selection = Utils.Decorate(
    Utils.Decorate(MultipleSelection, Placeholder),
    AllowClear
  );

  var selection = new Selection(
    $element,
    allowClearOptions
  );
  var container = new MockContainer();

  var $container = $(
    '<span class="select2-container select2-container--default"></span>'
  );
  $('#qunit-fixture').append($container);

  var $selection = selection.render();
github select2 / select2 / tests / utils / decorator-tests.js View on Github external
return decorated.call(this, a + 'b');
  };

  function DecoratorClass (decorated, testArgument) {
    this.decoratorCalled = true;
    this.decoratorTestArgument = testArgument;

    decorated.call(this, testArgument);
  }

  DecoratorClass.prototype.test = function (decorated, a) {
    return decorated.call(this, a + 'a');
  };

  var DecoratedClass = Utils.Decorate(
    Utils.Decorate(BaseClass, MiddleClass),
    DecoratorClass
  );

  var inst = new DecoratedClass('test');

  assert.ok(inst.baseCalled, 'The base class contructor was called');
  assert.ok(inst.middleCalled, 'The middle class constructor was called');
  assert.ok(inst.decoratorCalled, 'The decorator constructor was called');

  assert.strictEqual(inst.baseTestArgument, 'test');
  assert.strictEqual(inst.middleTestArgument, 'test');
  assert.strictEqual(inst.decoratorTestArgument, 'test');

  var out = inst.test('test');

  assert.strictEqual(out, 'testabc');
github select2 / select2 / tests / dropdown / search-a11y-tests.js View on Github external
module('Dropdown - Search - Accessibility');

var Utils = require('select2/utils');

var Dropdown = require('select2/dropdown');
var DropdownSearch = Utils.Decorate(
  Dropdown,
  require('select2/dropdown/search')
);

var $ = require('jquery');

var Options = require('select2/options');
var options = new Options({});

test('role attribute is set to searchbox', function (assert) {
  var $select = $('#qunit-fixture .single');

  var dropdown = new DropdownSearch($select, options);
  var $dropdown = dropdown.render();

  var container = new MockContainer();
github select2 / select2 / tests / utils / decorator-tests.js View on Github external
MiddleClass.prototype.test = function (decorated, a) {
    return decorated.call(this, a + 'b');
  };

  function DecoratorClass (decorated, testArgument) {
    this.decoratorCalled = true;
    this.decoratorTestArgument = testArgument;

    decorated.call(this, testArgument);
  }

  DecoratorClass.prototype.test = function (decorated, a) {
    return decorated.call(this, a + 'a');
  };

  var DecoratedClass = Utils.Decorate(
    Utils.Decorate(BaseClass, MiddleClass),
    DecoratorClass
  );

  var inst = new DecoratedClass('test');

  assert.ok(inst.baseCalled, 'The base class contructor was called');
  assert.ok(inst.middleCalled, 'The middle class constructor was called');
  assert.ok(inst.decoratorCalled, 'The decorator constructor was called');

  assert.strictEqual(inst.baseTestArgument, 'test');
  assert.strictEqual(inst.middleTestArgument, 'test');
  assert.strictEqual(inst.decoratorTestArgument, 'test');

  var out = inst.test('test');
github select2 / select2 / tests / selection / allowClear-tests.js View on Github external
module('Selection containers - Placeholders - Allow clear');

var Placeholder = require('select2/selection/placeholder');
var AllowClear = require('select2/selection/allowClear');

var SingleSelection = require('select2/selection/single');
var MultipleSelection = require('select2/selection/multiple');

var $ = require('jquery');
var Options = require('select2/options');
var Utils = require('select2/utils');

var AllowClearPlaceholder = Utils.Decorate(
  Utils.Decorate(SingleSelection, Placeholder),
  AllowClear
);

var allowClearOptions = new Options({
  placeholder: {
    id: 'placeholder',
    text: 'This is the placeholder'
  },
  allowClear: true
});

test('clear is not displayed for single placeholder', function (assert) {
  var selection = new AllowClearPlaceholder(
    $('#qunit-fixture .single-with-placeholder'),
    allowClearOptions
  );
github select2 / select2 / tests / selection / search-placeholder-tests.js View on Github external
module('Selection containers - Inline search - Placeholder');

var MultipleSelection = require('select2/selection/multiple');
var InlineSearch = require('select2/selection/search');
var SelectionPlaceholder = require('select2/selection/placeholder');

var $ = require('jquery');
var Options = require('select2/options');
var Utils = require('select2/utils');

var CustomSelection = Utils.Decorate(
  Utils.Decorate(MultipleSelection, SelectionPlaceholder),
  InlineSearch
);

test('width does not extend the search box', function (assert) {
    assert.expect(2);

    var $container = $(
      '<div style="width: 100px; display: table-cell">' +
      '<div style="width: 100%"></div>' +
      '</div>'
    );
    var container = new MockContainer();

    var $element = $('#qunit-fixture .multiple');
github select2 / select2 / tests / dropdown / dropdownCss-tests.js View on Github external
module('Dropdown - dropdownCssClass compatibility');

var $ = require('jquery');
var Utils = require('select2/utils');
var Options = require('select2/options');

var Dropdown = require('select2/dropdown');
var DropdownCSS = Utils.Decorate(
  Dropdown,
  require('select2/compat/dropdownCss')
);

test('all classes will be copied if :all: is used', function (assert) {
  var $element = $('<select class="test copy works"></select>');
  var options = new Options({
    dropdownCssClass: ':all:'
  });

  var select = new DropdownCSS($element, options);
  var $dropdown = select.render();

  assert.ok($dropdown.hasClass('test'));
  assert.ok($dropdown.hasClass('copy'));
  assert.ok($dropdown.hasClass('works'));
github select2 / select2 / tests / data / inputData-tests.js View on Github external
module('Data adapters - <input> compatibility');

var $ = require('jquery');

var Options = require('select2/options');
var Utils = require('select2/utils');

var ArrayData = require('select2/data/array');
var InputData = require('select2/compat/inputData');

var InputAdapter = Utils.Decorate(ArrayData, InputData);

test('test that options can be selected', function (assert) {
  var options = new Options({
    data: [
      {
        id: 'test',
        text: 'Test'
      }
    ]
  });
  var $element = $('<input>');

  var adapter = new InputAdapter($element, options);

  var container = new MockContainer();
  adapter.bind(container, $('<div></div>'));

select2

Select2 is a jQuery based replacement for select boxes. It supports searching, remote data sets, and infinite scrolling of results.

MIT
Latest version published 4 years ago

Package Health Score

82 / 100
Full package analysis