paulchew88
paulchew88

Reputation: 3

How do I dynamically set a max value on a number type in Thymleaf

I am working on a Ecommerce application and want to dynamically set the maximum amount of a product that can be added to a cart depending on the quantity that is left. my Html code is currently

<tr>
                    <th>quantity</th>
                    <td><input type="number" min="1" max="${product.stockQuantity}" value="1" name="qty" /></td>
                </tr>

This does not limit the amount that can be added.

Upvotes: 0

Views: 994

Answers (1)

Marco Dalla Santa
Marco Dalla Santa

Reputation: 361

I think you should use th:max according to official documentation: https://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#setting-attribute-values

Upvotes: 1

Related Questions