Validate quantity inputs

master
Mark Moffat 2020-01-08 19:42:32 +10:30
parent 3bda249c68
commit fb6fb6e3e0
3 changed files with 24 additions and 1 deletions

View File

@ -305,6 +305,14 @@ $(document).ready(function (){
});
});
$('#product_quantity').on('keyup', function(e){
checkMaxQuantity(e, $('#product_quantity'));
});
$('.cart-product-quantity').on('keyup', function(e){
checkMaxQuantity(e, $('.cart-product-quantity'));
});
$('.cart-product-quantity').on('focusout', function(e){
cartUpdate($(e.target));
});
@ -391,6 +399,20 @@ $(document).ready(function (){
}
});
function checkMaxQuantity(e, element){
if($('#maxQuantity').length){
if(e.keyCode === 46 || e.keyCode === 8){
return;
}
if(parseInt($(e.target).val()) > parseInt($('#maxQuantity').val())){
const qty = element.val();
e.preventDefault();
element.val(qty.slice(0, -1));
showNotification(`Exceeds maximum quantity: ${$('#maxQuantity').val()}`, 'warning', false);
}
}
}
function deleteFromCart(element){
$.ajax({
method: 'POST',

File diff suppressed because one or more lines are too long

View File

@ -166,6 +166,7 @@
<input type="hidden" id="cartCheckout" value="{{checkout}}">
<input type="hidden" id="cartTheme" value="{{@root.config.theme}}">
<input type="hidden" id="currencySymbol" value="{{@root.config.currencySymbol}}">
{{#if @root.config.maxQuantity}} <input type="hidden" id="maxQuantity" value="{{@root.config.maxQuantity}}">{{/if}}
<div id="notify_message"></div>
{{#if showFooter}}
<footer class="footer">