Skip to content

Instantly share code, notes, and snippets.

@JumboLove
Created July 9, 2013 17:48
Show Gist options
  • Select an option

  • Save JumboLove/5959525 to your computer and use it in GitHub Desktop.

Select an option

Save JumboLove/5959525 to your computer and use it in GitHub Desktop.
Increment/Decrement Button
<input type="text" name="${FormLi.quantity.htmlName}" size="2" maxlength="6" value="<isprint value="${lineItem.quantity}"/>" data-pid="${lineItem.productID}" class="inputbox quantityinput positivenumber" />
<iscomment>Plus and Minus button functionality</iscomment>
<isif condition="${lineItem.quantity > 0}">
<button class="plus quantitybtn" data-pid="${lineItem.productID}">Plus</button>
<button class="minus quantitybtn" data-pid="${lineItem.productID}">Minus</button>
</isif>
jQuery(".cart .quantitybtn").click(function(){
var productID = jQuery(this).attr("data-pid");
var inputField = jQuery(".cart .quantitycolumn input[data-pid=" + productID + "]");
var oldValue = inputField.val();
if(jQuery(this).hasClass("plus")){
var newValue = oldValue < app.cart.maxNumber ? parseInt(oldValue) + 1 : oldValue;
} else {
var newValue = oldValue > app.cart.minNumber ? parseInt(oldValue) - 1 : oldValue;
}
//Set the new value and trigger a change
inputField.val(newValue);
if(newValue !== oldValue){
inputField.trigger("change");
}
return false;
});
jQuery(".cart .quantityinput").change(function(){
console.log("changed");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment