Skip to content

Commit

Permalink
Fixed unit tests and updated source code to handle HTML5 attribs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadim Afana committed May 6, 2016
1 parent 95b1f8b commit a1dc7f2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/js/select2/options.js
Expand Up @@ -78,7 +78,8 @@ define([
}

$e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
Utils.StoreData($e[0], 'ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));

This comment has been minimized.

Copy link
@billyeh

billyeh Dec 18, 2017

Why was this change made? I think it should be ajax--url

This comment has been minimized.

Copy link
@alexweissman

alexweissman Dec 19, 2017

Contributor

@NadeemAfana could you address this question?

This comment has been minimized.

Copy link
@NadeemAfana

NadeemAfana Dec 20, 2017

This is to mimic the old behavior using html5 data attributes. It is not clear what issue are you having.
Can you submit a complete working example showing any problems you have ?

This comment has been minimized.

Copy link
@billyeh

billyeh Dec 20, 2017

Sorry for the contextless comment. Have you seen #5169? That's where I provide some more information.

}

var dataset = {};
Expand Down
8 changes: 5 additions & 3 deletions src/js/select2/utils.js
Expand Up @@ -303,11 +303,13 @@ define([
var id = Utils.GetUniqueElementId(element);
if (name) {
if (Utils.__cache[id]) {
return Utils.__cache[id][name];
return Utils.__cache[id][name] != null ?
Utils.__cache[id][name]:
$(element).data(name); // Fallback to HTML5 data attribs.
}
return null;
return $(element).data(name); // Fallback to HTML5 data attribs.
} else {
return Utils.__cache[id];
return Utils.__cache[id];
}
};

Expand Down
5 changes: 3 additions & 2 deletions tests/data/array-tests.js
Expand Up @@ -3,6 +3,7 @@ module('Data adapters - Array');
var ArrayData = require('select2/data/array');
var $ = require('jquery');
var Options = require('select2/options');
var Utils = require('select2/utils');

var arrayOptions = new Options({
data: [
Expand Down Expand Up @@ -237,7 +238,7 @@ test('option tags can receive new data', function(assert) {
});

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

Expand All @@ -246,7 +247,7 @@ test('option tags can receive new data', function(assert) {
});

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

0 comments on commit a1dc7f2

Please sign in to comment.