Files
korea-research/front/src/main/resources/templates/user/info.html

127 lines
3.9 KiB
HTML

<!DOCTYPE html>
<html layout:decorate="~{layout/layout}" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
xmlns:th="http://www.thymeleaf.org">
<section layout:fragment="content">
<style>
label {
display: inline-block;
width: 150px;
}
div {
margin-bottom: 15px;
}
.invalid-feedback {
display: none;
font-size: 12px;
font-weight: bold;
}
.is-invalid + .invalid-feedback {
display: block;
}
input[readonly] {
background-color: #e9ecef;
color: #6c757d;
cursor: not-allowed;
}
</style>
<div>
<form
method="get"
name="reqForm"
th:action="@{/user/info}" th:object="${userInfo}">
<input type="hidden" name="id" th:value="*{seq}">
<div>
<label for="householdNum">임가번호</label>
<input id="householdNum" name="householdNum" placeholder="아이디" readonly="readonly" th:field="*{householdNum}"
type="text">
<div class="invalid-feedback field-id"></div>
</div>
<div>
<label for="ownerName">경영주</label>
<input id="ownerName" name="ownerName" placeholder="경영주 이름" th:field="*{ownerName}" type="text">
<div class="invalid-feedback field-id"></div>
</div>
<div>
<label for="ownerAge">만나이</label>
<input id="ownerAge" name="ownerAge" placeholder="나이" th:field="*{ownerAge}" type="text">
<div class="invalid-feedback field-id"></div>
</div>
<div>
<label for="tel">가구연락처</label>
<input id="tel" name="tel" placeholder="가구연락처" th:field="*{tel}" type="text">
<div class="invalid-feedback field-id"></div>
</div>
<div>
<label for="phone">핸드폰번호</label>
<input id="phone" name="phone" placeholder="핸드폰번호" th:field="*{phone}" type="text">
<div class="invalid-feedback field-id"></div>
</div>
<div>
<label for="region">시.도</label>
<input id="region" name="region" placeholder="시.도" th:field="*{region}" type="text">
<div class="invalid-feedback field-id"></div>
</div>
<div>
<label for="city">시.군.도</label>
<input id="city" name="city" placeholder="시.군.도" th:field="*{city}" type="text">
<div class="invalid-feedback field-id"></div>
</div>
<div>
<label for="addressDetail">세부 주소</label>
<input id="addressDetail" name="addressDetail" placeholder="세부 주소" th:field="*{addressDetail}" type="text">
<div class="invalid-feedback field-id"></div>
</div>
</form>
<button onclick="updateUser();">수정하기</button>
</div>
</section>
<section layout:fragment="script">
<script>
const updateUser = () => {
const f = document.reqForm;
const obj = $(f).serializeObject();
// 기존 에러 메세지 초기화
$('.is-invalid').removeClass('is-invalid');
$.ajax({
method: 'PATCH',
url: '/api/front/household/update',
data: obj,
beforeSend: function (xhr) {
xhr.setRequestHeader(
$("meta[name='_csrf_header']").attr("content"),
$("meta[name='_csrf']").attr("content"));
},
success(res) {
if (confirm(`'${res.ownerName} 님의' 정보가 수정되었습니다.`)) {
location.reload();
}
},
statusCode: {
'422': (res) => {
const fieldErrors = res.responseJSON.fieldErrors;
$(fieldErrors).each(function (idx, error) {
let target = $(f).find('[name=' + error.field + ']');
target.addClass('is-invalid');
target.parent().find('.invalid-feedback').text(error.message);
});
}
}
})
}
</script>
</section>
</html>