Magento 2 limit max length in Qty field
Question
I wan't to know how to set a max length for the Qty field that is when you click a product (I guess it's product View)
I tried to override the following template and set maxlength = "4"
but did not work.
magento/module-catalog/view/frontend/templates/product/view/addtocart.phtml
What template should I override or what item can I modify in the layout to allow just 4 digits in Qty field?
Thanks!
Solution
What you're describing is a limitation of the html 5 element, not of Magento or your process. That is indeed the location you would need to change, and when I make the edit you described I see it on my front-end when I view source. The problem you're describing is that the input type "number" ignores maxlength.
There are solutions at this thread on regular stack overflow. I wouldn't recommend changing the field to text (although this would work) because it breaks the mobile experience. There are some simple javascript validation techniques described at that link.