Reputation: 23
How I can set a checked attribute for an input in my form, using Thymeleaf? Here is my code, which currently doesn't work:
<label th:each="cat : ${categories}">
<input type="checkbox" value=""
th:value="${cat.id}"
th:text="${cat.description}"
th:checked="${recipe.getCategories().contains(cat) ? true : false}"
/>
</label>
Upvotes: 1
Views: 3149
Reputation: 24482
As stated in comments, the problem may be from somewhere else but try this and see if it helps:
th:checked="${recipe.getCategories().contains(cat)}"
Upvotes: 1