Number input "max" not showing on Product form but works in cart

I am trying to put a max qty limit on the qty input of the product page.

On my product-form file I’m including

{% if item.product.tags contains 'max5' %}
    <input type="number" min="1" max="5" size="2" class="quantity" name="updates[]" id="updates_{{ item.id }}" value="{{ item.quantity }}" data-cart-quantity-input="cart-template"  />
  {% elsif item.product.tags contains 'max4' %} ...........

on the product page - the max=“5” disappears. I can change any other number such as size, min or value and it updates just fine. but the results on the Product page look like this (notice Max is missing)

<input type="number" min="1" size="2" class="quantity" name="quantity" id="quantity" value="1">

I am using nearly identical code in the cart - and it works fine there

{% if item.product.tags contains 'max5' %}
    <input type="number" min="1" max="5" size="2" class="quantity" name="updates[]" id="updates_{{ item.id }}" value="{{ item.quantity }}" data-cart-quantity-input="cart-template"  />
  {% elsif item.product.tags contains 'max4' %}....

Dawn theme.

1 Like

Hi @JoeCat

I see your max number changes. The cleaner way to do this is use product metafield to assign the max for you

This is the metafield settings I used

  1. From your Admin Page, click Online Store > Themes >Actions > Edit code
  2. In the Section folder, open the main-product.liquid
  3. Find the quantity__input, then below the min=“1”, paste the code below
{% if product.metafields.custom.max_number != blank  %}max="{{ product.metafields.custom.max_number }}"{% endif %}

See image for code placement

  1. We have to do the same in the cart page.

  2. In the Section folder, open the main-cart-items.liquid

  3. Find the quantity__input, then below the min=“1”, paste the code below

{% if product.metafields.custom.max_number != blank  %}max="{{ product.metafields.custom.max_number }}"{% endif %}

See image below for placement