Quantcast

No check visible in Checkbox when condition evaluates to True.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

No check visible in Checkbox when condition evaluates to True.

apprentice
This post was updated on .
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No check visible in Checkbox when condition evaluates to True.

danielfernandez
Administrator
When you are using th:field, the "checked" property of your checkboxes is automatically dealt with by Thymeleaf. You should simply not specify it.

See an example in one of our example applications here: https://github.com/thymeleaf/thymeleafexamples-stsm/blob/6d0e71f7a89f50825ae0d369c0e6aeba6728cc4a/src/main/webapp/WEB-INF/templates/seedstartermng.html#L94-L97

Regards,
Daniel.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No check visible in Checkbox when condition evaluates to True.

apprentice
This does not work either.

<li th:each="makeType : ${T(com.enum.MakeType).values()}">
          <input type="checkbox" th:value="${makeType}" th:field="*{makes}" />
         <label th:for="${makeType}" th:text="${makeType}"></label>
</li>
...

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No check visible in Checkbox when condition evaluates to True.

danielfernandez
Administrator
It should work. Could you please re-check that the "makes" property is correctly initialized when the execution reaches the template and it does really contain the values you were expecting?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: No check visible in Checkbox when condition evaluates to True.

apprentice
Here is the relevant classes and form snippets. What did I miss?
 
Relevant Class snippets

public class Vehical{
...
    private Set<Make> makes = AppUtil.newHashSetInstance();
 
}

public class Make {
    @Enumerated(EnumType.STRING)
    private MakeType makeType;
    ....
}

public enum MakeType {
     one,
     two,
     three
}

Form

<form accept-charset="UTF-8" th:object="${account.vehical}" th:action="@{...}" method="post"

<li th:each="makeType : ${T(com.enum.MakeType).values()}">
          <input type="checkbox" th:value="${makeType}" th:field="*{makes}" />
         <label th:for="${makeType}" th:text="${makeType}"></label>
</li>

...

</field>



Loading...