Added decorator to remove the placeholder object
This will remove the placeholder object from the results list.
This commit is contained in:
parent
09a0bb89b8
commit
e57e0b1870
52
dist/js/select2.amd.full.js
vendored
52
dist/js/select2.amd.full.js
vendored
@ -1395,6 +1395,49 @@ define('select2/dropdown/search',[
|
||||
return Search;
|
||||
});
|
||||
|
||||
define('select2/dropdown/hidePlaceholder',[
|
||||
|
||||
], function () {
|
||||
function HidePlaceholder (decorated, $element, options, dataAdapter) {
|
||||
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
||||
|
||||
decorated.call(this, $element, options, dataAdapter);
|
||||
}
|
||||
|
||||
HidePlaceholder.prototype.append = function (decorated, data) {
|
||||
data = this.removePlaceholder(data);
|
||||
|
||||
decorated.call(this, data);
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
|
||||
if (typeof placeholder === 'string') {
|
||||
placeholder = {
|
||||
id: '',
|
||||
text: placeholder
|
||||
};
|
||||
}
|
||||
|
||||
return placeholder;
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
|
||||
var modifiedData = data.slice(0);
|
||||
|
||||
for (var d = data.length - 1; d >= 0; d--) {
|
||||
var item = data[d];
|
||||
|
||||
if (this.placeholder.id === item.id) {
|
||||
modifiedData.splice(d, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return modifiedData;
|
||||
};
|
||||
|
||||
return HidePlaceholder;
|
||||
});
|
||||
|
||||
define('select2/i18n/en',[],function () {
|
||||
return {
|
||||
noResults: function () {
|
||||
@ -1421,13 +1464,15 @@ define('select2/defaults',[
|
||||
|
||||
'./dropdown',
|
||||
'./dropdown/search',
|
||||
'./dropdown/hidePlaceholder',
|
||||
|
||||
'./i18n/en'
|
||||
], function ($, ResultsList,
|
||||
SingleSelection, MultipleSelection, Placeholder,
|
||||
Utils, Translation,
|
||||
SelectData, ArrayData, AjaxData, Tags,
|
||||
Dropdown, Search, EnglishTranslation) {
|
||||
Dropdown, Search, HidePlaceholder,
|
||||
EnglishTranslation) {
|
||||
function Defaults () {
|
||||
this.reset();
|
||||
}
|
||||
@ -1472,6 +1517,11 @@ define('select2/defaults',[
|
||||
options.selectionAdapter,
|
||||
Placeholder
|
||||
);
|
||||
|
||||
options.resultsAdapter = Utils.Decorate(
|
||||
options.resultsAdapter,
|
||||
HidePlaceholder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
52
dist/js/select2.amd.js
vendored
52
dist/js/select2.amd.js
vendored
@ -1395,6 +1395,49 @@ define('select2/dropdown/search',[
|
||||
return Search;
|
||||
});
|
||||
|
||||
define('select2/dropdown/hidePlaceholder',[
|
||||
|
||||
], function () {
|
||||
function HidePlaceholder (decorated, $element, options, dataAdapter) {
|
||||
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
||||
|
||||
decorated.call(this, $element, options, dataAdapter);
|
||||
}
|
||||
|
||||
HidePlaceholder.prototype.append = function (decorated, data) {
|
||||
data = this.removePlaceholder(data);
|
||||
|
||||
decorated.call(this, data);
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
|
||||
if (typeof placeholder === 'string') {
|
||||
placeholder = {
|
||||
id: '',
|
||||
text: placeholder
|
||||
};
|
||||
}
|
||||
|
||||
return placeholder;
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
|
||||
var modifiedData = data.slice(0);
|
||||
|
||||
for (var d = data.length - 1; d >= 0; d--) {
|
||||
var item = data[d];
|
||||
|
||||
if (this.placeholder.id === item.id) {
|
||||
modifiedData.splice(d, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return modifiedData;
|
||||
};
|
||||
|
||||
return HidePlaceholder;
|
||||
});
|
||||
|
||||
define('select2/i18n/en',[],function () {
|
||||
return {
|
||||
noResults: function () {
|
||||
@ -1421,13 +1464,15 @@ define('select2/defaults',[
|
||||
|
||||
'./dropdown',
|
||||
'./dropdown/search',
|
||||
'./dropdown/hidePlaceholder',
|
||||
|
||||
'./i18n/en'
|
||||
], function ($, ResultsList,
|
||||
SingleSelection, MultipleSelection, Placeholder,
|
||||
Utils, Translation,
|
||||
SelectData, ArrayData, AjaxData, Tags,
|
||||
Dropdown, Search, EnglishTranslation) {
|
||||
Dropdown, Search, HidePlaceholder,
|
||||
EnglishTranslation) {
|
||||
function Defaults () {
|
||||
this.reset();
|
||||
}
|
||||
@ -1472,6 +1517,11 @@ define('select2/defaults',[
|
||||
options.selectionAdapter,
|
||||
Placeholder
|
||||
);
|
||||
|
||||
options.resultsAdapter = Utils.Decorate(
|
||||
options.resultsAdapter,
|
||||
HidePlaceholder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
52
dist/js/select2.full.js
vendored
52
dist/js/select2.full.js
vendored
@ -10930,6 +10930,49 @@ define('select2/dropdown/search',[
|
||||
return Search;
|
||||
});
|
||||
|
||||
define('select2/dropdown/hidePlaceholder',[
|
||||
|
||||
], function () {
|
||||
function HidePlaceholder (decorated, $element, options, dataAdapter) {
|
||||
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
||||
|
||||
decorated.call(this, $element, options, dataAdapter);
|
||||
}
|
||||
|
||||
HidePlaceholder.prototype.append = function (decorated, data) {
|
||||
data = this.removePlaceholder(data);
|
||||
|
||||
decorated.call(this, data);
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
|
||||
if (typeof placeholder === 'string') {
|
||||
placeholder = {
|
||||
id: '',
|
||||
text: placeholder
|
||||
};
|
||||
}
|
||||
|
||||
return placeholder;
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
|
||||
var modifiedData = data.slice(0);
|
||||
|
||||
for (var d = data.length - 1; d >= 0; d--) {
|
||||
var item = data[d];
|
||||
|
||||
if (this.placeholder.id === item.id) {
|
||||
modifiedData.splice(d, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return modifiedData;
|
||||
};
|
||||
|
||||
return HidePlaceholder;
|
||||
});
|
||||
|
||||
define('select2/i18n/en',[],function () {
|
||||
return {
|
||||
noResults: function () {
|
||||
@ -10956,13 +10999,15 @@ define('select2/defaults',[
|
||||
|
||||
'./dropdown',
|
||||
'./dropdown/search',
|
||||
'./dropdown/hidePlaceholder',
|
||||
|
||||
'./i18n/en'
|
||||
], function ($, ResultsList,
|
||||
SingleSelection, MultipleSelection, Placeholder,
|
||||
Utils, Translation,
|
||||
SelectData, ArrayData, AjaxData, Tags,
|
||||
Dropdown, Search, EnglishTranslation) {
|
||||
Dropdown, Search, HidePlaceholder,
|
||||
EnglishTranslation) {
|
||||
function Defaults () {
|
||||
this.reset();
|
||||
}
|
||||
@ -11007,6 +11052,11 @@ define('select2/defaults',[
|
||||
options.selectionAdapter,
|
||||
Placeholder
|
||||
);
|
||||
|
||||
options.resultsAdapter = Utils.Decorate(
|
||||
options.resultsAdapter,
|
||||
HidePlaceholder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
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
52
dist/js/select2.js
vendored
52
dist/js/select2.js
vendored
@ -1823,6 +1823,49 @@ define('select2/dropdown/search',[
|
||||
return Search;
|
||||
});
|
||||
|
||||
define('select2/dropdown/hidePlaceholder',[
|
||||
|
||||
], function () {
|
||||
function HidePlaceholder (decorated, $element, options, dataAdapter) {
|
||||
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
||||
|
||||
decorated.call(this, $element, options, dataAdapter);
|
||||
}
|
||||
|
||||
HidePlaceholder.prototype.append = function (decorated, data) {
|
||||
data = this.removePlaceholder(data);
|
||||
|
||||
decorated.call(this, data);
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
|
||||
if (typeof placeholder === 'string') {
|
||||
placeholder = {
|
||||
id: '',
|
||||
text: placeholder
|
||||
};
|
||||
}
|
||||
|
||||
return placeholder;
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
|
||||
var modifiedData = data.slice(0);
|
||||
|
||||
for (var d = data.length - 1; d >= 0; d--) {
|
||||
var item = data[d];
|
||||
|
||||
if (this.placeholder.id === item.id) {
|
||||
modifiedData.splice(d, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return modifiedData;
|
||||
};
|
||||
|
||||
return HidePlaceholder;
|
||||
});
|
||||
|
||||
define('select2/i18n/en',[],function () {
|
||||
return {
|
||||
noResults: function () {
|
||||
@ -1849,13 +1892,15 @@ define('select2/defaults',[
|
||||
|
||||
'./dropdown',
|
||||
'./dropdown/search',
|
||||
'./dropdown/hidePlaceholder',
|
||||
|
||||
'./i18n/en'
|
||||
], function ($, ResultsList,
|
||||
SingleSelection, MultipleSelection, Placeholder,
|
||||
Utils, Translation,
|
||||
SelectData, ArrayData, AjaxData, Tags,
|
||||
Dropdown, Search, EnglishTranslation) {
|
||||
Dropdown, Search, HidePlaceholder,
|
||||
EnglishTranslation) {
|
||||
function Defaults () {
|
||||
this.reset();
|
||||
}
|
||||
@ -1900,6 +1945,11 @@ define('select2/defaults',[
|
||||
options.selectionAdapter,
|
||||
Placeholder
|
||||
);
|
||||
|
||||
options.resultsAdapter = Utils.Decorate(
|
||||
options.resultsAdapter,
|
||||
HidePlaceholder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
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
9
src/js/select2/defaults.js
vendored
9
src/js/select2/defaults.js
vendored
@ -16,13 +16,15 @@ define([
|
||||
|
||||
'./dropdown',
|
||||
'./dropdown/search',
|
||||
'./dropdown/hidePlaceholder',
|
||||
|
||||
'./i18n/en'
|
||||
], function ($, ResultsList,
|
||||
SingleSelection, MultipleSelection, Placeholder,
|
||||
Utils, Translation,
|
||||
SelectData, ArrayData, AjaxData, Tags,
|
||||
Dropdown, Search, EnglishTranslation) {
|
||||
Dropdown, Search, HidePlaceholder,
|
||||
EnglishTranslation) {
|
||||
function Defaults () {
|
||||
this.reset();
|
||||
}
|
||||
@ -67,6 +69,11 @@ define([
|
||||
options.selectionAdapter,
|
||||
Placeholder
|
||||
);
|
||||
|
||||
options.resultsAdapter = Utils.Decorate(
|
||||
options.resultsAdapter,
|
||||
HidePlaceholder
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
42
src/js/select2/dropdown/hidePlaceholder.js
vendored
Normal file
42
src/js/select2/dropdown/hidePlaceholder.js
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
define([
|
||||
|
||||
], function () {
|
||||
function HidePlaceholder (decorated, $element, options, dataAdapter) {
|
||||
this.placeholder = this.normalizePlaceholder(options.get('placeholder'));
|
||||
|
||||
decorated.call(this, $element, options, dataAdapter);
|
||||
}
|
||||
|
||||
HidePlaceholder.prototype.append = function (decorated, data) {
|
||||
data = this.removePlaceholder(data);
|
||||
|
||||
decorated.call(this, data);
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.normalizePlaceholder = function (_, placeholder) {
|
||||
if (typeof placeholder === 'string') {
|
||||
placeholder = {
|
||||
id: '',
|
||||
text: placeholder
|
||||
};
|
||||
}
|
||||
|
||||
return placeholder;
|
||||
};
|
||||
|
||||
HidePlaceholder.prototype.removePlaceholder = function (_, data) {
|
||||
var modifiedData = data.slice(0);
|
||||
|
||||
for (var d = data.length - 1; d >= 0; d--) {
|
||||
var item = data[d];
|
||||
|
||||
if (this.placeholder.id === item.id) {
|
||||
modifiedData.splice(d, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return modifiedData;
|
||||
};
|
||||
|
||||
return HidePlaceholder;
|
||||
});
|
Loading…
Reference in New Issue
Block a user