| @@ -176,6 +176,15 @@ | |||||
| const successAlert = document.getElementById('formSuccessMessage'); | const successAlert = document.getElementById('formSuccessMessage'); | ||||
| const submitButtonContainer = document.getElementById('submitButtonContainer'); | const submitButtonContainer = document.getElementById('submitButtonContainer'); | ||||
| const showError = (message) => { | |||||
| if (!errorAlert || !errorText) { | |||||
| alert(message); | |||||
| return; | |||||
| } | |||||
| errorText.textContent = message; | |||||
| errorAlert.classList.remove('d-none'); | |||||
| }; | |||||
| const hideError = () => { | const hideError = () => { | ||||
| if (!errorAlert || !errorText) { | if (!errorAlert || !errorText) { | ||||
| return; | return; | ||||
| @@ -186,6 +195,13 @@ | |||||
| errorCloseBtn?.addEventListener('click', hideError); | errorCloseBtn?.addEventListener('click', hideError); | ||||
| const optionalGroup = [ | |||||
| document.querySelector('input[name="InvoiceData.Email"]'), | |||||
| document.querySelector('input[name="InvoiceData.CarrierID"]'), | |||||
| document.querySelector('input[name="InvoiceData.BuyerIdentifier"]'), | |||||
| document.querySelector('select[name="InvoiceData.LoveCode"]') | |||||
| ]; | |||||
| const form = document.querySelector('form[method="post"]'); | const form = document.querySelector('form[method="post"]'); | ||||
| if (!form) { | if (!form) { | ||||
| return; | return; | ||||
| @@ -218,6 +234,19 @@ | |||||
| return; | return; | ||||
| } | } | ||||
| const filledCount = optionalGroup.reduce((count, field) => { | |||||
| if (field && field.value.trim() !== '') { | |||||
| return count + 1; | |||||
| } | |||||
| return count; | |||||
| }, 0); | |||||
| if (filledCount === 0) { | |||||
| event.preventDefault(); | |||||
| showError('Email、手機條碼、購買者統編、捐贈碼需擇一填寫,請填寫任一項。'); | |||||
| return; | |||||
| } | |||||
| hideError(); | hideError(); | ||||
| lockForm(); | lockForm(); | ||||
| }); | }); | ||||