개인정보 변경 유효성 체크까지 수정
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
</div>
|
||||
<div class="select-scroll">
|
||||
<ul class="">
|
||||
<li class="option" data-value="" th:classappend="${userInfo.tel1 == ''?' current':'' }">선택</li>
|
||||
<li class="option" data-value="02" th:classappend="${userInfo.tel1 == '02'?' current':'' }">02</li>
|
||||
<li class="option" data-value="031" th:classappend="${userInfo.tel1 == '031'?' current':'' }">31</li>
|
||||
<li class="option" data-value="033" th:classappend="${userInfo.tel1 == '033'?' current':'' }">033</li>
|
||||
@@ -135,7 +136,6 @@
|
||||
</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div id="regionSubCodeId" class="component-select bottom-sheet" data-props-default="지역 선택"
|
||||
data-props-type="bottomSheet">
|
||||
<input type="hidden" name="regionSubCode" data-type="select" th:value="${userInfo.regionSubCode}">
|
||||
@@ -150,7 +150,6 @@
|
||||
</button>
|
||||
</div>
|
||||
<div class="select-scroll">
|
||||
|
||||
<ul class="">
|
||||
<!-- <th:block th:each="item : ${regionMainList}">-->
|
||||
<!-- <li class="option" th:data-value="${item.id}"-->
|
||||
@@ -197,7 +196,7 @@
|
||||
</div>
|
||||
<div class="component-input">
|
||||
<div class="input-field">
|
||||
<input type="text" id="temp_input_00023" placeholder="세부 주소를 입력해 주세요"
|
||||
<input type="text" id="temp_input_00023" placeholder="전체 주소를 입력해 주세요"
|
||||
th:field="*{address}" maxlength="50"/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -363,66 +362,73 @@
|
||||
// selectboxInstance1.setValue($('input[name=regionMainCode]').val());
|
||||
},
|
||||
confirmPopup() {
|
||||
//유효성 검사
|
||||
const form = document.getElementById('reqForm');
|
||||
kri.form.errorInit(form);
|
||||
const selects = ['tel1', 'phone1', 'regionSubCode', 'regionDetailCode'];
|
||||
selects.forEach(id => {
|
||||
const sel = document.getElementById(id);
|
||||
if (sel && sel.value) form[id].value = sel.value;
|
||||
});
|
||||
|
||||
const errors = [];
|
||||
if (!form.ownerName.value) errors.push({field: 'ownerName', message: '이름을 입력해 주세요.'});
|
||||
if (!form.ownerAge.value) errors.push({field: 'ownerAge', message: '연령을 입력해 주세요.'});
|
||||
if (form.ownerAge.value < 0 || form.ownerAge.value > 120) errors.push({field: 'ownerAge', message: '연령은 0세이상 120세 이하이어야 합니다.'});
|
||||
if (form.tel1.value || form.tel2.value || form.tel3.value) {
|
||||
if (!form.tel1.value || !form.tel2.value || !form.tel3.value) {
|
||||
errors.push({ field: 'tel1', message: '가구 연락처를 모두 입력해 주세요.' });
|
||||
} else {
|
||||
const telRegex = /^(0[2-7][0-9]?)$/; // 지역번호 (예: 02, 031, 032 등)
|
||||
if (!telRegex.test(form.tel1.value)) errors.push({ field: 'tel1', message: '가구 연락처를 입력해주세요' }); // 유효한 지역번호를 선택해 주세요.
|
||||
if (form.tel2.value.length < 3 || form.tel2.value.length > 4) errors.push({ field: 'tel2', message: '가구 연락처를 입력해주세요.' });// 가구 연락처 중간 자리수는 3~4자리여야 합니다.
|
||||
if (form.tel3.value.length !== 4) errors.push({ field: 'tel3', message: '가구 연락처를 입력해주세요.' }); // 가구 연락처 마지막 자리수는 4자리여야 합니다.
|
||||
}
|
||||
}
|
||||
if (form.phone1.value || form.phone2.value || form.phone3.value) {
|
||||
if (form.tel2.value.length === 3) errors.push({ field: 'tel1', message: '핸드폰 번호를 입력해 주세요.' });
|
||||
if (form.tel2.value.length < 3 || form.tel2.value.length > 4) errors.push({ field: 'tel2', message: '핸드폰 번호를 입력해 주세요.' });
|
||||
if (form.tel3.value.length !== 4) errors.push({ field: 'tel3', message: '핸드폰 번호를 입력해 주세요.' });
|
||||
}
|
||||
if (!form.phone1.value ||!form.phone2.value || !form.phone3.value) errors.push({field: 'phone1', message: '휴대폰 번호를 입력해 주세요.'});
|
||||
if (form.phone1.value.length < 2 || form.phone2.value.length < 3 || form.phone2.value.length > 4 || form.phone3.value.length < 3 || form.phone3.value.length > 4) errors.push({field: 'phone1', message: '휴대폰 번호를 입력해 주세요.'});
|
||||
if (!form.regionSubCode.value) errors.push({field: 'regionSubCode', message: '지역을 선택해 주세요.'});
|
||||
if (!form.regionDetailCode.value) errors.push({field: 'regionDetailCode', message: '세부 지역를 선택해 주세요.'});
|
||||
if (!form.address.value) errors.push({field: 'address', message: '전체 주소를 입력해 주세요.'});
|
||||
|
||||
kri.form.error(errors);
|
||||
if (errors.length > 0) return;
|
||||
|
||||
// 이름 변경 여부 처리
|
||||
const currentName = document.querySelector('input[name="ownerName"]').value.trim();
|
||||
const isNameChanged = currentName !== ENV.initialOwnerName;
|
||||
|
||||
formControl.updateUserInfo(isNameChanged);
|
||||
if(isNameChanged){
|
||||
ENV.module.confirmPopup.open();
|
||||
}else {
|
||||
formControl.updateUserInfo();
|
||||
}
|
||||
},
|
||||
confirmPopupOk() {
|
||||
ENV.module.confirmPopup.close();
|
||||
|
||||
setTimeout(() => {
|
||||
ajaxUtil._alert('개인정보 변경이 완료되었습니다.', null, () => {
|
||||
location.href = '/info';
|
||||
});
|
||||
}, 500);
|
||||
formControl.updateUserInfo();
|
||||
},
|
||||
updateUserInfo(showPopupIfValidNameChanged = false) {
|
||||
|
||||
updateUserInfo() {
|
||||
const f = document.reqForm;
|
||||
// // TODO 어쩔수 없이 이렇게 하는데..... 콤포넌트값 핸들링 방법 UX에서 지정하면 수정해야함.
|
||||
// const tel1Element = document.getElementById('tel1Id');
|
||||
// const phone1IdElement = document.getElementById('phone1Id');
|
||||
// const regionMainCodeIdElement = document.getElementById('regionMainCodeId');
|
||||
// const regionSubCodeIdElement = document.getElementById('regionSubCodeId');
|
||||
// if (tel1Element && tel1Element.value) {
|
||||
// f.tel1.value = tel1Element.value;
|
||||
// }
|
||||
// if (phone1IdElement && phone1IdElement.value) {
|
||||
// f.phone1.value = phone1IdElement.value;
|
||||
// }
|
||||
// if (regionMainCodeIdElement && regionMainCodeIdElement.value) {
|
||||
// f.regionMainCode.value = regionMainCodeIdElement.value;
|
||||
// }
|
||||
// if (regionSubCodeIdElement && regionSubCodeIdElement.value) {
|
||||
// f.regionSubCode.value = regionSubCodeIdElement.value;
|
||||
// }
|
||||
|
||||
f.regionSubCode.value = ENV.select.regionSelect.getParentValue();
|
||||
f.regionDetailCode.value = ENV.select.regionSelect.getChildValue();
|
||||
f.tel1.value = ENV.select.selectTel.getValue();
|
||||
f.phone1.value = ENV.select.selectPhone.getValue();
|
||||
|
||||
|
||||
|
||||
|
||||
const obj = $(f).serializeObject();
|
||||
console.log(obj)
|
||||
ajaxUtil._ajaxAsync(
|
||||
ENV.httpUrl.user,
|
||||
obj,
|
||||
$(f).serializeObject(),
|
||||
function (rstData, status) {
|
||||
if (rstData.code === 'SUCCESS') {
|
||||
// 유효성 검사를 모두 통과한 후
|
||||
if (showPopupIfValidNameChanged) {
|
||||
// 이름이 바뀐 경우만 팝업
|
||||
ENV.module.confirmPopup.open();
|
||||
} else {
|
||||
ajaxUtil._alert('개인정보 변경이 완료되었습니다.', null, () => {
|
||||
location.href = '/info';
|
||||
});
|
||||
}
|
||||
ajaxUtil._alert('개인정보 변경이 완료되었습니다.', null, () => {
|
||||
location.href = '/info';
|
||||
});
|
||||
} else if (rstData.code === 'ERROR') {
|
||||
ajaxUtil._alert('잠시 뒤에 다시 시도해 주세요.', null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user