문제 상황
템플릿 적용 때문에 버튼을 form 내부에 넣으면 원하는 레이아웃이 나오지 않아서 버튼을 외부로 빼야했다.
해결 방법
- form 태그에는 id 속성 부여
<form id=”updateForm”>
- submit 버튼에는 form 속성 부여
<button type="submit" form="updateForm">Submit</button>
사용 예시
<form id="updateForm" th:action="@{/update}" method="post" th:object="${board}">
<input type="hidden" id="id" th:field="*{id}">
<input type="hidden" id="createdAt" th:field="*{createdAt}">
<div class="form-floating">
<input type="text" class="form-control" id="name" th:field="*{name}" readonly>
<label for="name">Name</label>
</div>
<div class="form-floating">
<input type="text" class="form-control" id="title" th:field="*{title}" required>
<label for="title">Title</label>
<div class="form-text" th:if="${#fields.hasErrors('title')}" th:errors="*{title}"></div>
</div>
<div class="form-floating">
<textarea class="form-control" id="content" th:field="*{content}" style="height: 12rem" required></textarea>
<label for="content">Content</label>
<div class="form-text" th:if="${#fields.hasErrors('content')}" th:errors="*{content}"></div>
</div>
<div class="form-floating">
<input type="password" class="form-control" id="password" th:field="*{password}" required>
<label for="password">Password for verification</label>
<div class="form-text" th:if="${#fields.hasErrors('password')}" th:errors="*{password}"></div>
</div>
<br />
</form>
<!-- Submit Button-->
<div class="button-group">
<button class="btn btn-primary text-uppercase" id="submitButton" type="submit" form="updateForm">Submit</button>
<a th:href="@{/list}" class="btn btn-success text-uppercase" id="listButton">List</a>
</div>
'🔫 트러블슈팅' 카테고리의 다른 글
[카카오 지도 API] 같은 장소인데 다른 좌표로 판단하는 부동소수점 오차 문제 (0) | 2024.09.18 |
---|---|
[카카오 지도 API] 마커 인덱스가 index+1 값으로 표시되는 문제 (0) | 2024.09.13 |
[카카오 지도 API] 검색 결과 목록의 페이지별 마커 인덱스 겹침 문제 (0) | 2024.09.13 |
[Spring Boot] BindingResult를 통한 유효성 검증 시 잘못된 BindingResult 위치 (0) | 2024.06.13 |
[Spring Boot] input type=hidden으로 컨트롤러에 값 넘겨주기 (0) | 2024.06.08 |