ccgenerative's picture
Hey can you please add patient registration module as well
3bcbb3b verified
Raw
History Blame Contribute Delete
2.06 kB
// Main JavaScript functionality
document.addEventListener('DOMContentLoaded', function() {
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Mobile menu toggle functionality will be handled by navbar component
// Form validation for registration
const validateForm = (form) => {
const inputs = form.querySelectorAll('input[required]');
let isValid = true;
inputs.forEach(input => {
if (!input.value.trim()) {
input.classList.add('border-red-500');
isValid = false;
} else {
input.classList.remove('border-red-500');
}
});
// Email validation
const email = form.querySelector('#email');
if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email.value)) {
email.classList.add('border-red-500');
isValid = false;
}
// Password validation (min 8 chars)
const password = form.querySelector('#password');
if (password && password.value.length < 8) {
password.classList.add('border-red-500');
isValid = false;
}
return isValid;
};
// Attach validation to all forms with class 'needs-validation'
document.querySelectorAll('form').forEach(form => {
form.addEventListener('submit', function(e) {
if (!validateForm(this)) {
e.preventDefault();
e.stopPropagation();
}
});
// Clear validation errors when typing
form.querySelectorAll('input').forEach(input => {
input.addEventListener('input', function() {
this.classList.remove('border-red-500');
});
});
});
});