How to use the select2/utils.GetData 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 / integration / jquery-calls.js View on Github external
$select.select2({maximumSelectionLength: 2, multiple: true});
  
  assert.equal(
    $select.val(),
    '3',
    'Only 1 option should be pulled.'
  );

  // Try to resolve instance via .data('select2').
  var $instance = $select.data('select2'); 
  assert.ok($instance);
  assert.ok($instance.options);

  // Ensure $select.data('select2') is the same instance 
  // created by .select2()   
  assert.equal($instance, Utils.GetData($instance.$element[0], 
               'select2'));
   
  // Ensure initialized property matches.
  assert.equal($instance.options.options.maximumSelectionLength,
               2);
});
github select2 / select2 / tests / data / array-tests.js View on Github external
test('automatically generated option tags have a result id', function (assert) {
  var $select = $('#qunit-fixture .single-empty');

  var data = new ArrayData($select, arrayOptions);

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

  data.select({
    id: 'default'
  });

  assert.ok(
    Utils.GetData($select.find(':selected')[0], 'data')._resultId,
    '<option> default should have a result ID assigned'
  );
});
</option>
github select2 / select2 / tests / data / array-tests.js View on Github external
var container = new MockContainer();
  data.bind(container, $('<div></div>'));

  assert.equal(
    $select.find('option').length,
    2,
    'Only one more <option> element should be created'
  );

  data.select({
    id: 'default'
  });

  assert.ok(
    Utils.GetData($select.find(':selected')[0], 'data').extra,
    '</option><option> default should have new data'
  );

  data.select({
    id: 'One'
  });

  assert.ok(
    Utils.GetData($select.find(':selected')[0], 'data').extra,
    '</option><option> One should have new data'
  );
});
</option>

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

79 / 100
Full package analysis