mirror of
https://github.com/ansible/awx.git
synced 2026-02-17 03:00:04 -03:30
smooth out logic for adding new options to single select to select2
This commit is contained in:
@@ -624,7 +624,12 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
|||||||
addNew = params.addNew,
|
addNew = params.addNew,
|
||||||
scope = params.scope,
|
scope = params.scope,
|
||||||
options = params.options,
|
options = params.options,
|
||||||
model = params.model;
|
model = params.model,
|
||||||
|
original_options;
|
||||||
|
|
||||||
|
if (scope && options) {
|
||||||
|
original_options = _.cloneDeep(scope[options]);
|
||||||
|
}
|
||||||
|
|
||||||
$.fn.select2.amd.require([
|
$.fn.select2.amd.require([
|
||||||
'select2/utils',
|
'select2/utils',
|
||||||
@@ -664,7 +669,6 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
|||||||
config.tokenSeparators = [];
|
config.tokenSeparators = [];
|
||||||
|
|
||||||
if (!multiple) {
|
if (!multiple) {
|
||||||
scope["original_" + options] = scope[options];
|
|
||||||
config.minimumResultsForSearch = 1;
|
config.minimumResultsForSearch = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -691,13 +695,12 @@ angular.module('Utilities', ['RestServices', 'Utilities'])
|
|||||||
|
|
||||||
if (addNew && !multiple) {
|
if (addNew && !multiple) {
|
||||||
$(element).on('select2:select', (e) => {
|
$(element).on('select2:select', (e) => {
|
||||||
var opt = $(e.target).find("[data-select2-tag='true']");
|
scope[model] = e.params.data.text;
|
||||||
if (opt.length) {
|
scope[options] = _.cloneDeep(original_options);
|
||||||
scope[model] = e.params.data.id;
|
if (scope[options].indexOf(e.params.data.text) === -1) {
|
||||||
scope[options] = scope["original_" + options];
|
scope[options].push(e.params.data.text);
|
||||||
scope[options].push($(opt[0]).attr("value"));
|
|
||||||
}
|
}
|
||||||
$(element).trigger('change');
|
$(element).select2(config);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user