Merge pull request #5441 from devansh-webkul/quantity-changer-fixed

Default Quantity Changer Fixed #5440
This commit is contained in:
Devansh 2021-12-17 14:02:42 +05:30 committed by GitHub
commit 74742c5cf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 13 deletions

View File

@ -199,12 +199,19 @@
<button type="button" class="decrease" @click="decreaseQty()">-</button>
<input :name="controlName" class="control" :value="qty" v-validate="'required|numeric|min_value:1'" data-vv-as="&quot;{{ __('shop::app.products.quantity') }}&quot;" readonly>
<input
ref="quantityChanger"
class="control"
:name="controlName"
:model="qty"
v-validate="validations"
data-vv-as="&quot;{{ __('shop::app.products.quantity') }}&quot;"
@keyup="setQty($event)">
<button type="button" class="increase" @click="increaseQty()">+</button>
<span class="control-error" v-if="errors.has(controlName)">@{{ errors.first(controlName) }}</span>
</div>
<span class="control-error" v-if="errors.has(controlName)">@{{ errors.first(controlName) }}</span>
</div>
</script>
@ -223,6 +230,16 @@
quantity: {
type: [Number, String],
default: 1
},
minQuantity: {
type: [Number, String],
default: 1
},
validations: {
type: String,
default: 'required|numeric|min_value:1'
}
},
@ -232,26 +249,32 @@
}
},
watch: {
quantity: function (val) {
this.qty = val;
mounted: function() {
this.$refs.quantityChanger.value = this.qty > this.minQuantity
? this.qty
: this.minQuantity;
},
this.$emit('onQtyUpdated', this.qty)
watch: {
qty: function (val) {
this.$refs.quantityChanger.value = val;
this.$emit('onQtyUpdated', this.qty);
}
},
methods: {
decreaseQty: function() {
if (this.qty > 1)
this.qty = parseInt(this.qty) - 1;
setQty: function({ target }) {
this.qty = parseInt(target.value);
},
this.$emit('onQtyUpdated', this.qty)
decreaseQty: function() {
if (this.qty > this.minQuantity)
this.qty = parseInt(this.qty) - 1;
},
increaseQty: function() {
this.qty = parseInt(this.qty) + 1;
this.$emit('onQtyUpdated', this.qty)
}
}
});