Strip whitespace by default for tags
This strips whitespace in tags by default, so multiple tags cannot be created with only whitespace as the difference in the id. A test has been added to ensure that this remains fixed in the future. This closes https://github.com/select2/select2/issues/3076.
This commit is contained in:
parent
95be140760
commit
610381be4a
12
dist/js/select2.amd.full.js
vendored
12
dist/js/select2.amd.full.js
vendored
@ -2845,7 +2845,7 @@ define('select2/data/tags',[
|
|||||||
|
|
||||||
this._removeOldTags();
|
this._removeOldTags();
|
||||||
|
|
||||||
if (params.term == null || params.term === '' || params.page != null) {
|
if (params.term == null || params.page != null) {
|
||||||
decorated.call(this, params, callback);
|
decorated.call(this, params, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2901,9 +2901,15 @@ define('select2/data/tags',[
|
|||||||
};
|
};
|
||||||
|
|
||||||
Tags.prototype.createTag = function (decorated, params) {
|
Tags.prototype.createTag = function (decorated, params) {
|
||||||
|
var term = $.trim(params.term);
|
||||||
|
|
||||||
|
if (term === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: params.term,
|
id: term,
|
||||||
text: params.term
|
text: term
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
12
dist/js/select2.amd.js
vendored
12
dist/js/select2.amd.js
vendored
@ -2845,7 +2845,7 @@ define('select2/data/tags',[
|
|||||||
|
|
||||||
this._removeOldTags();
|
this._removeOldTags();
|
||||||
|
|
||||||
if (params.term == null || params.term === '' || params.page != null) {
|
if (params.term == null || params.page != null) {
|
||||||
decorated.call(this, params, callback);
|
decorated.call(this, params, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -2901,9 +2901,15 @@ define('select2/data/tags',[
|
|||||||
};
|
};
|
||||||
|
|
||||||
Tags.prototype.createTag = function (decorated, params) {
|
Tags.prototype.createTag = function (decorated, params) {
|
||||||
|
var term = $.trim(params.term);
|
||||||
|
|
||||||
|
if (term === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: params.term,
|
id: term,
|
||||||
text: params.term
|
text: term
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
12
dist/js/select2.full.js
vendored
12
dist/js/select2.full.js
vendored
@ -3284,7 +3284,7 @@ define('select2/data/tags',[
|
|||||||
|
|
||||||
this._removeOldTags();
|
this._removeOldTags();
|
||||||
|
|
||||||
if (params.term == null || params.term === '' || params.page != null) {
|
if (params.term == null || params.page != null) {
|
||||||
decorated.call(this, params, callback);
|
decorated.call(this, params, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3340,9 +3340,15 @@ define('select2/data/tags',[
|
|||||||
};
|
};
|
||||||
|
|
||||||
Tags.prototype.createTag = function (decorated, params) {
|
Tags.prototype.createTag = function (decorated, params) {
|
||||||
|
var term = $.trim(params.term);
|
||||||
|
|
||||||
|
if (term === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: params.term,
|
id: term,
|
||||||
text: params.term
|
text: term
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
dist/js/select2.full.min.js
vendored
2
dist/js/select2.full.min.js
vendored
File diff suppressed because one or more lines are too long
12
dist/js/select2.js
vendored
12
dist/js/select2.js
vendored
@ -3284,7 +3284,7 @@ define('select2/data/tags',[
|
|||||||
|
|
||||||
this._removeOldTags();
|
this._removeOldTags();
|
||||||
|
|
||||||
if (params.term == null || params.term === '' || params.page != null) {
|
if (params.term == null || params.page != null) {
|
||||||
decorated.call(this, params, callback);
|
decorated.call(this, params, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -3340,9 +3340,15 @@ define('select2/data/tags',[
|
|||||||
};
|
};
|
||||||
|
|
||||||
Tags.prototype.createTag = function (decorated, params) {
|
Tags.prototype.createTag = function (decorated, params) {
|
||||||
|
var term = $.trim(params.term);
|
||||||
|
|
||||||
|
if (term === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: params.term,
|
id: term,
|
||||||
text: params.term
|
text: term
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
2
dist/js/select2.min.js
vendored
2
dist/js/select2.min.js
vendored
File diff suppressed because one or more lines are too long
12
src/js/select2/data/tags.js
vendored
12
src/js/select2/data/tags.js
vendored
@ -29,7 +29,7 @@ define([
|
|||||||
|
|
||||||
this._removeOldTags();
|
this._removeOldTags();
|
||||||
|
|
||||||
if (params.term == null || params.term === '' || params.page != null) {
|
if (params.term == null || params.page != null) {
|
||||||
decorated.call(this, params, callback);
|
decorated.call(this, params, callback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -85,9 +85,15 @@ define([
|
|||||||
};
|
};
|
||||||
|
|
||||||
Tags.prototype.createTag = function (decorated, params) {
|
Tags.prototype.createTag = function (decorated, params) {
|
||||||
|
var term = $.trim(params.term);
|
||||||
|
|
||||||
|
if (term === '') {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id: params.term,
|
id: term,
|
||||||
text: params.term
|
text: term
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,6 +38,32 @@ test('does not trigger on blank or null terms', function (assert) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('white space is trimmed by default', function (assert) {
|
||||||
|
var data = new SelectTags($('#qunit-fixture .single'), options);
|
||||||
|
|
||||||
|
data.query({
|
||||||
|
term: ' '
|
||||||
|
}, function (data) {
|
||||||
|
assert.equal(data.results.length, 1);
|
||||||
|
|
||||||
|
var item = data.results[0];
|
||||||
|
|
||||||
|
assert.equal(item.id, 'One');
|
||||||
|
assert.equal(item.text, 'One');
|
||||||
|
});
|
||||||
|
|
||||||
|
data.query({
|
||||||
|
term: ' One '
|
||||||
|
}, function (data) {
|
||||||
|
assert.equal(data.results.length, 1);
|
||||||
|
|
||||||
|
var item = data.results[0];
|
||||||
|
|
||||||
|
assert.equal(item.id, 'One');
|
||||||
|
assert.equal(item.text, 'One');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('does not trigger for additional pages', function (assert) {
|
test('does not trigger for additional pages', function (assert) {
|
||||||
var data = new SelectTags($('#qunit-fixture .single'), options);
|
var data = new SelectTags($('#qunit-fixture .single'), options);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user