주관식 입력 폼 검증
This commit is contained in:
@@ -59,6 +59,47 @@ document.getElementById('step4Form').addEventListener('submit', async function(e
|
||||
const formData = new FormData(this);
|
||||
const data = Object.fromEntries(formData);
|
||||
|
||||
// 기타의견란에 작성해야 하는 문항 번호 찾기
|
||||
const requiredQuestions = [];
|
||||
const questionLabels = document.querySelectorAll('.doctrine-section .form-group label');
|
||||
questionLabels.forEach((label, index) => {
|
||||
const questionText = label.textContent.trim();
|
||||
if (questionText.includes('기타의견란') || questionText.includes('기타의견')) {
|
||||
// 문항 번호 추출 (예: "3. 예수님이..." -> 3)
|
||||
const match = questionText.match(/^(\d+)\./);
|
||||
if (match) {
|
||||
requiredQuestions.push(parseInt(match[1]));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 기타의견란 검증
|
||||
if (requiredQuestions.length > 0) {
|
||||
const otherOpinions = data.other_opinions || '';
|
||||
if (!otherOpinions.trim()) {
|
||||
const questionNums = requiredQuestions.map(n => n + '번').join(', ');
|
||||
alert(`${questionNums} 문항은 기타의견란에 작성해주세요.`);
|
||||
document.getElementById('other_opinions').focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// 각 필수 문항 번호가 기타의견란에 포함되어 있는지 확인
|
||||
const missingQuestions = [];
|
||||
for (const qNum of requiredQuestions) {
|
||||
if (!otherOpinions.includes(qNum + '번:')) {
|
||||
missingQuestions.push(qNum);
|
||||
}
|
||||
}
|
||||
|
||||
if (missingQuestions.length > 0) {
|
||||
const questionNums = missingQuestions.map(n => n + '번').join(', ');
|
||||
const questionFormats = missingQuestions.map(n => n + '번:').join(', ');
|
||||
alert(`${questionNums} 문항은 기타의견란에 "${questionFormats}"으로 시작하여 답변해주세요.`);
|
||||
document.getElementById('other_opinions').focus();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch('/step4', {
|
||||
method: 'POST',
|
||||
|
||||
Reference in New Issue
Block a user