diff --git a/src/pretix/static/pretixpresale/js/widget/widget.js b/src/pretix/static/pretixpresale/js/widget/widget.js index b7667f3ab1..b7ca374813 100644 --- a/src/pretix/static/pretixpresale/js/widget/widget.js +++ b/src/pretix/static/pretixpresale/js/widget/widget.js @@ -203,10 +203,10 @@ Vue.component('availbox', { + '' + '
' + ''), @@ -214,7 +214,32 @@ Vue.component('availbox', { item: Object, variation: Object }, + mounted: function() { + if (this.item.has_variations) { + this.$set(this.variation, 'amount_selected', 0); + } else { + // Automatically set the only available item to be selected. + this.$set(this.item, 'amount_selected', this.$root.itemnum === 1 ? 1 : 0); + } + this.$root.$emit('amounts_changed') + }, computed: { + amount_selected: { + get() { + return this.item.has_variations ? this.variation.amount_selected : this.item.amount_selected + }, + set(value) { + // Unary operator to force boolean to integer conversion, as the HTML form submission + // needs the value to be integer for all products. + value = (+value); + if (this.item.has_variations) { + this.variation.amount_selected = value; + } else { + this.item.amount_selected = value; + } + this.$root.$emit("amounts_changed") + } + }, input_name: function () { if (this.item.has_variations) { return 'variation_' + this.item.id + '_' + this.variation.id; @@ -222,7 +247,7 @@ Vue.component('availbox', { return 'item_' + this.item.id; } }, - order_max: function () { + order_max: function () { return this.item.has_variations ? this.variation.order_max : this.item.order_max; }, avail: function () { @@ -726,7 +751,7 @@ Vue.component('pretix-widget-event-form', { + '' + '