Skip to content

Commit a1dc7f2

Browse files
author
Nadim Afana
committed
Fixed unit tests and updated source code to handle HTML5 attribs.
1 parent 95b1f8b commit a1dc7f2

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

src/js/select2/options.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ define([
7878
}
7979

8080
$e.attr('ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
81-
Utils.StoreData($e[0], 'ajax--url', Utils.GetData($e[0], 'ajaxUrl'));
81+
Utils.StoreData($e[0], 'ajax-Url', Utils.GetData($e[0], 'ajaxUrl'));
82+
8283
}
8384

8485
var dataset = {};

src/js/select2/utils.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,13 @@ define([
303303
var id = Utils.GetUniqueElementId(element);
304304
if (name) {
305305
if (Utils.__cache[id]) {
306-
return Utils.__cache[id][name];
306+
return Utils.__cache[id][name] != null ?
307+
Utils.__cache[id][name]:
308+
$(element).data(name); // Fallback to HTML5 data attribs.
307309
}
308-
return null;
310+
return $(element).data(name); // Fallback to HTML5 data attribs.
309311
} else {
310-
return Utils.__cache[id];
312+
return Utils.__cache[id];
311313
}
312314
};
313315

tests/data/array-tests.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module('Data adapters - Array');
33
var ArrayData = require('select2/data/array');
44
var $ = require('jquery');
55
var Options = require('select2/options');
6+
var Utils = require('select2/utils');
67

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

239240
assert.ok(
240-
$select.find(':selected').data('data').extra,
241+
Utils.GetData($select.find(':selected')[0], 'data').extra,
241242
'<option> default should have new data'
242243
);
243244

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

248249
assert.ok(
249-
$select.find(':selected').data('data').extra,
250+
Utils.GetData($select.find(':selected')[0], 'data').extra,
250251
'<option> One should have new data'
251252
);
252253
});

0 commit comments

Comments
 (0)