In my template Thymeleaf in form:
<ul name="property" id="property" class="form-control mt-3">
<li th:each="property, el : ${tabs}">
<input type="checkbox" checked th:id="${el.count}" th:value="*{property.id}" th:field="*{shop.listOfProperty}" />
<label
th:text="${property.name}">Heating</label>
</li>
</ul>
- ${tabs} - list objects : List
- *{shop.listOfProperty} - list object in my object Shop : Shop.listOfProperty - List
In result:
<ul name="property" id="property" class="form-control mt-3">
<li class="" >
<input type="checkbox" id="1" value="1" name="listOfProperty" /><input type="hidden" name="_listOfProperty" value="on"/>
<label>FOOD</label>
</li>
<li class="" >
<input type="checkbox" id="2" value="2" name="listOfProperty" /><input type="hidden" name="_listOfProperty" value="on"/>
<label>CLOTHES</label>
</li>
<li class="" >
<input type="checkbox" id="3" value="3" name="listOfProperty" /><input type="hidden" name="_listOfProperty" value="on"/>
<label>BUILDING</label>
</li>
</ul>
I can't set a check for my checkbox in any way. I tried: checked, th:checked
I can to set checked if I not use th:field :
<li >
<input type="checkbox" th:id="${tabs[0].id}" checked="checked" th:value="${tabs[0].id}" />
<label
th:text="${tabs[0].name}">Heating</label>
</li>