Home > Net >  Value attribute is missing after adding thymeleaf's tag th:field to input
Value attribute is missing after adding thymeleaf's tag th:field to input

Time:01-25

Here is my form, I have one input where value is 0. It works perfectly fine until I add th:field="*{dishQuantityMap[__${dish.id}__]}".

   <div  th:each="dish : ${dishList}">
        <form action="#" th:action="@{/menu}" th:object="${order}" method="post">
            <button   onclick="stepperDecrement(this)">-</button>
                            <input
                             th:field="*{dishQuantityMap[__${dish.id}__]}"
                                    type="number"
                                    min="0"
                                    max="100"
                                    step="1"
                                    value="0"/>
           <button   onclick="stepperIncrement(this)"> </button>
                <button type="submit" value="Submit" >Confirm order</button>
        </form>
     </div>

After that - value just disappears. Here is what I see in my page.enter image description here

CodePudding user response:

You can manually set the name/value/id like you're doing in the other question you asked, or you can set the value in your map for each dish to 0 in your controller.

for (var dish: dishList) {
  dishQuantityMap.put(dish.getId(), 0);
}
  •  Tags:  
  • Related