Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Thymeleaf + Springboot + Bootstrap - Checkbox #326

Open
eventoul opened this issue Jul 5, 2024 · 1 comment
Open

Thymeleaf + Springboot + Bootstrap - Checkbox #326

eventoul opened this issue Jul 5, 2024 · 1 comment

Comments

@eventoul
Copy link

eventoul commented Jul 5, 2024

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.

@LalithK90
Copy link

yap @eventoul

I have the same issue but I manage it using the following

<input id="checkboxCourses"  
		type="checkbox" 
		class="form-check-input" 
		th:value="${course.id}" 
		name="courses"                
		th:checked="${course.mandatory}"
          />

There is an assumption that course.mandatory variable value is "selected"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants