ruby on rails - Spree Commerce Number Input - JQuery -
i trying add simple plus/minus input box on each product on categories page of web app. add cart.
here html:
<div class="addqty"> <div class="qtycontents"> <a class="add">+</a> <%= number_field_tag :quantity, 1, :min => 1 %> <a class="minus">-</a> </div> </div> and here js:
$('.add').click(function () { $(this).next('#quantity').val(parseint($(this).next('#quantity').val(), 10) + 1); }); $('.minus').click(function () { $(this).prev('#quantity').val(parseint($(this).prev('#quantity').val(), 10) - 1); }); the issue having unique. when clicking "+" on first product on categories page, input not increased 1, increased number of products on page, minus 1. so, if there 10 products on page, , click "+" on first product, quantity in input goes 1 9, 18, 27 etc. , opposite when clicking "-". advance through products, increments become less - when on third last product, qty increases 2.
very confused. appreciated.
the problem spree holds add class products view , when values adding quantity items on page, should try changing class names code , jquery selectors.
Comments
Post a Comment