Merge pull request #5441 from devansh-webkul/quantity-changer-fixed
Default Quantity Changer Fixed #5440
This commit is contained in:
commit
74742c5cf7
|
|
@ -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=""{{ __('shop::app.products.quantity') }}"" readonly>
|
||||
<input
|
||||
ref="quantityChanger"
|
||||
class="control"
|
||||
:name="controlName"
|
||||
:model="qty"
|
||||
v-validate="validations"
|
||||
data-vv-as=""{{ __('shop::app.products.quantity') }}""
|
||||
@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)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue