Skip to content

Instantly share code, notes, and snippets.

@incrize
Created November 27, 2019 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incrize/025ddc95718dd83659dedc7222a146ff to your computer and use it in GitHub Desktop.
Save incrize/025ddc95718dd83659dedc7222a146ff to your computer and use it in GitHub Desktop.
diff --git a/js/core/src/core/Tygh/plugins/object_selector/index.js b/js/core/src/core/Tygh/plugins/object_selector/index.js
index 95811f55c0..75909b6c5a 100644
--- a/js/core/src/core/Tygh/plugins/object_selector/index.js
+++ b/js/core/src/core/Tygh/plugins/object_selector/index.js
@@ -199,11 +199,25 @@ $.extend(ObjectSelector.prototype, {
return object.context;
};
- if (this.settings.data) {
+ var elm = this.$el;
+
+ if (this.settings.data) {
select2config.data = this.settings.data;
- }
- var elm = this.$el;
+ if (Array.isArray(select2config.data)) {
+ var options = {};
+
+ elm.find('option').each(function () {
+ options[$(this).val()] = $(this);
+ });
+
+ this.settings.data.forEach(function (item) {
+ if (item.id && item.text && options[item.id] && !options[item.id].text()) {
+ options[item.id].text(item.text);
+ }
+ });
+ }
+ }
if (this.settings.templateSelectionSelector ||
this.settings.enableImages ||
diff --git a/js/tygh/backend/promotion_update.js b/js/tygh/backend/promotion_update.js
index 64ddc316de..fc2d575f4e 100644
--- a/js/tygh/backend/promotion_update.js
+++ b/js/tygh/backend/promotion_update.js
@@ -115,13 +115,15 @@
this.$childInput.addClass('hidden');
this.$childSelect.prop('disabled', false);
- if (loadViaAjax && this.$childSelect.val()) {
+ var value = $.makeArray(this.$childSelect.val()).filter(function (val) { return Boolean(val); } );
+
+ if (loadViaAjax && value.length) {
var self = this;
$.ceAjax('request', childSelect2Settings.dataUrl, {
hidden: true,
caching: false,
data: {
- preselected: this.$childSelect.val(),
+ preselected: value,
page_size: 0
},
callback: function (data) {
@@ -134,7 +136,6 @@
object.selected = true;
});
childSelect2Settings.data = childPreselectedObjects;
- self.$childSelect.empty().val(null).trigger('change');
self.$childSelect.ceObjectSelector(childSelect2Settings);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment