Spaces:
Running
Running
File size: 6,853 Bytes
b6f3763 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 | let currentStep = 1;
const totalSteps = 7;
// Initialize
document.addEventListener('DOMContentLoaded', function() {
updateUI();
setupEventListeners();
setupFileUploads();
setupConditionalFields();
});
function setupEventListeners() {
// Checkbox card styling
document.querySelectorAll('.condition-checkbox').forEach(checkbox => {
checkbox.addEventListener('change', function() {
const card = this.closest('.checkbox-card');
if (this.checked) {
card.classList.add('selected');
} else {
card.classList.remove('selected');
}
});
});
// Keyboard navigation
document.addEventListener('keydown', function(e) {
if (e.key === 'Enter' && e.target.tagName !== 'TEXTAREA') {
e.preventDefault();
if (currentStep < totalSteps) {
changeStep(1);
}
}
});
}
function setupFileUploads() {
// File drop zones
document.querySelectorAll('.file-drop-zone').forEach(zone => {
const input = zone.querySelector('input[type="file"]');
zone.addEventListener('dragover', (e) => {
e.preventDefault();
zone.classList.add('dragover');
});
zone.addEventListener('dragleave', () => {
zone.classList.remove('dragover');
});
zone.addEventListener('drop', (e) => {
e.preventDefault();
zone.classList.remove('dragover');
const files = e.dataTransfer.files;
if (files.length > 0) {
handleFileSelect(zone, files[0]);
}
});
input.addEventListener('change', (e) => {
if (e.target.files.length > 0) {
handleFileSelect(zone, e.target.files[0]);
}
});
});
}
function handleFileSelect(zone, file) {
// Visual feedback for file selection
zone.style.borderColor = '#0e9692';
zone.style.backgroundColor = '#e6f5f4';
const icon = zone.querySelector('i');
const text = zone.querySelector('p.font-medium');
icon.setAttribute('data-lucide', 'check-circle');
icon.classList.remove('text-gray-400');
icon.classList.add('text-primary');
lucide.createIcons();
text.textContent = file.name;
text.classList.add('text-primary', 'font-medium');
// Add file size info
const sizeText = zone.querySelector('p.text-xs');
sizeText.textContent = `${(file.size / 1024 / 1024).toFixed(2)} MB uploaded`;
sizeText.classList.add('text-primary');
}
function setupConditionalFields() {
// Show/hide expiration date based on current patient status
const currentPatientRadios = document.querySelectorAll('input[name="current-patient"]');
const expirationField = document.getElementById('expiration-field');
currentPatientRadios.forEach(radio => {
radio.addEventListener('change', function() {
if (this.value === 'yes') {
expirationField.classList.remove('hidden');
} else {
expirationField.classList.add('hidden');
}
});
});
}
function changeStep(direction) {
const newStep = currentStep + direction;
if (newStep >= 1 && newStep <= totalSteps) {
// Hide current step
document.getElementById(`step-${currentStep}`).classList.add('hidden');
// Show new step
document.getElementById(`step-${newStep}`).classList.remove('hidden');
currentStep = newStep;
updateUI();
// Scroll to top of form
document.querySelector('main').scrollTop = 0;
}
}
function updateUI() {
// Update progress bar
const progress = (currentStep / totalSteps) * 100;
document.getElementById('progress-bar').style.width = `${progress}%`;
document.getElementById('step-indicator').textContent = `Step ${currentStep} of ${totalSteps}`;
document.getElementById('progress-percent').textContent = `${Math.round(progress)}%`;
// Update buttons
const backBtn = document.getElementById('btn-back');
const nextBtn = document.getElementById('btn-next');
const submitBtn = document.getElementById('btn-submit');
// Back button visibility
if (currentStep === 1) {
backBtn.classList.add('opacity-0', 'pointer-events-none');
} else {
backBtn.classList.remove('opacity-0', 'pointer-events-none');
}
// Next/Submit button toggle
if (currentStep === totalSteps) {
nextBtn.classList.add('hidden');
submitBtn.classList.remove('hidden');
} else {
nextBtn.classList.remove('hidden');
submitBtn.classList.add('hidden');
}
}
function submitForm() {
// Simulate form submission
const container = document.getElementById('form-container');
const currentSection = document.getElementById(`step-${currentStep}`);
// Hide current step
currentSection.classList.add('hidden');
// Hide footer buttons
document.getElementById('btn-back').style.visibility = 'hidden';
document.getElementById('btn-submit').classList.add('hidden');
// Show success message
const successSection = document.getElementById('step-success');
successSection.classList.remove('hidden');
// Update progress to 100%
document.getElementById('progress-bar').style.width = '100%';
document.getElementById('step-indicator').textContent = 'Complete';
document.getElementById('progress-percent').textContent = '100%';
// Success animation
container.style.transform = 'scale(0.98)';
setTimeout(() => {
container.style.transform = 'scale(1)';
}, 200);
// In a real application, you would submit the form data here
console.log('Form submitted successfully');
}
// Auto-format phone numbers
document.querySelectorAll('input[type="tel"]').forEach(input => {
input.addEventListener('input', function(e) {
let value = e.target.value.replace(/\D/g, '');
if (value.length > 0 && value.length <= 10) {
if (value.length > 6) {
value = `(${value.slice(0, 3)}) ${value.slice(3, 6)}-${value.slice(6)}`;
} else if (value.length > 3) {
value = `(${value.slice(0, 3)}) ${value.slice(3)}`;
} else if (value.length > 0) {
value = `(${value}`;
}
}
e.target.value = value;
});
});
// Handle window resize for mobile optimization
let resizeTimer;
window.addEventListener('resize', function() {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(function() {
// Ensure layout stays optimized
document.querySelector('main').scrollTop = 0;
}, 250);
}); |