This commit is contained in:
@@ -37,11 +37,15 @@ export function validatePhoneLive(inputEl) {
|
||||
|
||||
// Prevent form submission if phone is invalid
|
||||
function preventInvalidSubmission() {
|
||||
const forms = document.querySelectorAll('form');
|
||||
forms.forEach(form => {
|
||||
const phoneInputs = document.querySelectorAll('#phoneInput');
|
||||
phoneInputs.forEach(phoneInput => {
|
||||
const form = phoneInput.closest('form');
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
|
||||
form.addEventListener('submit', function (e) {
|
||||
const phoneInput = document.getElementById('phoneInput');
|
||||
if (phoneInput && !validatePhoneLive(phoneInput)) {
|
||||
if (!validatePhoneLive(phoneInput)) {
|
||||
e.preventDefault();
|
||||
phoneInput.focus();
|
||||
return false;
|
||||
@@ -53,6 +57,9 @@ function preventInvalidSubmission() {
|
||||
// Initialize the event listener when the page loads
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const phoneInput = document.getElementById('phoneInput');
|
||||
if (!phoneInput) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add input event listener for live validation and formatting
|
||||
phoneInput.addEventListener('input', function () {
|
||||
@@ -71,4 +78,4 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
// Prevent form submission for invalid phone numbers
|
||||
preventInvalidSubmission();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user