thymeleaf-spring icon indicating copy to clipboard operation
thymeleaf-spring copied to clipboard

Thymeleaf + Springboot + Bootstrap - Checkbox

Open eventoul opened this issue 1 year ago • 1 comments

Hi!

I have an issue with the code below:

`

                        <tr th:each="course : ${department.courses}">

                            <th th:text="${course.id}"></th>
                            <th th:text="${course.title}"></th>
                            <th th:text="${course.mandatory}"></th>
                            <th th:text="${course.duration}"></th>
                            <th th:text="${course.credits}"></th>
                            <th>
                                <div class="form-check">
                                    <label class="form-check-label" for="checkboxCourses"></label>
                                    <input id="checkboxCourses"  type="checkbox"
                                           class="form-check-input"
                                           th:value="${course.id}"
                                           th:field="*{courses}"
                                           th:checked="${course.mandatory}"
                                    />
                                </div>
                            </th>
                        </tr>
                    </tbody>`

I want the checkbox to be checked when a course is mandatory.

The th:field="*{courses}" refers to a Student model, which has a many-to-many relationship with the Course model.

I noticed that the th:checked="${course.mandatory}" works when I didn't have the th:field, but then I can't bind the course.id to save it in DB.

Any ideas?

PS: I want to be checked and disabled.

eventoul avatar Jul 05 '24 11:07 eventoul