forked from CGM_Public/pretix_original
Check-in rule editor: Fix reactivity issue in select2 component
This commit is contained in:
@@ -10,25 +10,29 @@
|
|||||||
' <slot></slot>\n' +
|
' <slot></slot>\n' +
|
||||||
' </select>'),
|
' </select>'),
|
||||||
mounted: function () {
|
mounted: function () {
|
||||||
var vm = this;
|
this.build();
|
||||||
var multiple = this.multiple;
|
|
||||||
$(this.$el)
|
|
||||||
.select2(this.opts())
|
|
||||||
.val(this.value || "")
|
|
||||||
.trigger("change")
|
|
||||||
// emit event on change.
|
|
||||||
.on("change", function (e) {
|
|
||||||
vm.$emit("input", $(this).select2('data'));
|
|
||||||
});
|
|
||||||
if (vm.value) {
|
|
||||||
for (var i = 0; i < vm.value["objectList"].length; i++) {
|
|
||||||
var option = new Option(vm.value["objectList"][i]["lookup"][2], vm.value["objectList"][i]["lookup"][1], true, true);
|
|
||||||
$(vm.$el).append(option);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$(vm.$el).trigger("change");
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
build: function () {
|
||||||
|
var vm = this;
|
||||||
|
var multiple = this.multiple;
|
||||||
|
$(this.$el)
|
||||||
|
.empty()
|
||||||
|
.select2(this.opts())
|
||||||
|
.val(this.value || "")
|
||||||
|
.trigger("change")
|
||||||
|
// emit event on change.
|
||||||
|
.on("change", function (e) {
|
||||||
|
vm.$emit("input", $(this).select2('data'));
|
||||||
|
});
|
||||||
|
if (vm.value) {
|
||||||
|
for (var i = 0; i < vm.value["objectList"].length; i++) {
|
||||||
|
var option = new Option(vm.value["objectList"][i]["lookup"][2], vm.value["objectList"][i]["lookup"][1], true, true);
|
||||||
|
$(vm.$el).append(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(vm.$el).trigger("change");
|
||||||
|
},
|
||||||
opts: function () {
|
opts: function () {
|
||||||
return {
|
return {
|
||||||
theme: "bootstrap",
|
theme: "bootstrap",
|
||||||
@@ -60,17 +64,29 @@
|
|||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
placeholder: function (val) {
|
placeholder: function (val) {
|
||||||
$(this.$el).empty().select2(this.opts());
|
$(this.$el).select2("destroy");
|
||||||
this.build();
|
this.build();
|
||||||
},
|
},
|
||||||
required: function (val) {
|
required: function (val) {
|
||||||
$(this.$el).empty().select2(this.opts());
|
$(this.$el).select2("destroy");
|
||||||
this.build();
|
this.build();
|
||||||
},
|
},
|
||||||
url: function (val) {
|
url: function (val) {
|
||||||
$(this.$el).empty().select2(this.opts());
|
$(this.$el).select2("destroy");
|
||||||
this.build();
|
this.build();
|
||||||
},
|
},
|
||||||
|
value: function (newval, oldval) {
|
||||||
|
if (JSON.stringify(newval) !== JSON.stringify(oldval)) {
|
||||||
|
$(this.$el).empty();
|
||||||
|
if (newval) {
|
||||||
|
for (var i = 0; i < newval["objectList"].length; i++) {
|
||||||
|
var option = new Option(newval["objectList"][i]["lookup"][2], newval["objectList"][i]["lookup"][1], true, true);
|
||||||
|
$(this.$el).append(option);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$(this.$el).trigger("change");
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
destroyed: function () {
|
destroyed: function () {
|
||||||
$(this.$el)
|
$(this.$el)
|
||||||
|
|||||||
Reference in New Issue
Block a user