Commit ed7cb45

bryfry <bryon@fryer.io>
2025-07-22 11:21:00
Remove redundant JavaScript validation
- Remove main.js file and script reference from base template - HTML5 form validation (required, type=email, type=url) already handles validation - Simplifies codebase and reduces unnecessary client-side complexity - Static file serving still works for CSS and images
1 parent f5b02dc
Changed files (2)
ui
html
layouts
static
ui/html/layouts/base.tmpl
@@ -36,8 +36,6 @@
             </div>
         </div>
     </footer>
-    
-    <script src="/static/js/main.js"></script>
 </body>
 </html>
 {{end}}
\ No newline at end of file
ui/static/js/main.js
@@ -1,163 +0,0 @@
-// Main JavaScript for buylater.email
-// Provides form validation and UX enhancements
-
-document.addEventListener('DOMContentLoaded', function() {
-    // Form validation for submit page
-    const submitForm = document.querySelector('.submit-form');
-    
-    if (submitForm) {
-        setupFormValidation(submitForm);
-    }
-
-    // Add smooth scrolling for anchor links
-    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
-        anchor.addEventListener('click', function (e) {
-            e.preventDefault();
-            const target = document.querySelector(this.getAttribute('href'));
-            if (target) {
-                target.scrollIntoView({
-                    behavior: 'smooth'
-                });
-            }
-        });
-    });
-});
-
-function setupFormValidation(form) {
-    const emailInput = form.querySelector('#email');
-    const urlInput = form.querySelector('#url');
-    const submitButton = form.querySelector('.submit-button');
-    
-    // Real-time validation for email
-    if (emailInput) {
-        emailInput.addEventListener('blur', function() {
-            validateEmail(this);
-        });
-        
-        emailInput.addEventListener('input', function() {
-            clearValidationError(this);
-        });
-    }
-    
-    // Real-time validation for URL
-    if (urlInput) {
-        urlInput.addEventListener('blur', function() {
-            validateUrl(this);
-        });
-        
-        urlInput.addEventListener('input', function() {
-            clearValidationError(this);
-        });
-    }
-    
-    // Form submission validation
-    form.addEventListener('submit', function(e) {
-        let isValid = true;
-        
-        if (emailInput && !validateEmail(emailInput)) {
-            isValid = false;
-        }
-        
-        if (urlInput && !validateUrl(urlInput)) {
-            isValid = false;
-        }
-        
-        if (!isValid) {
-            e.preventDefault();
-            showFormError('Please fix the errors above before submitting.');
-        } else {
-            // Show loading state
-            submitButton.textContent = 'Scheduling...';
-            submitButton.disabled = true;
-        }
-    });
-}
-
-function validateEmail(input) {
-    const email = input.value.trim();
-    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
-    
-    if (!email) {
-        showFieldError(input, 'Email address is required.');
-        return false;
-    }
-    
-    if (!emailRegex.test(email)) {
-        showFieldError(input, 'Please enter a valid email address.');
-        return false;
-    }
-    
-    clearValidationError(input);
-    return true;
-}
-
-function validateUrl(input) {
-    const url = input.value.trim();
-    
-    if (!url) {
-        showFieldError(input, 'Product URL is required.');
-        return false;
-    }
-    
-    try {
-        const urlObj = new URL(url);
-        if (!['http:', 'https:'].includes(urlObj.protocol)) {
-            throw new Error('Invalid protocol');
-        }
-    } catch (e) {
-        showFieldError(input, 'Please enter a valid URL (including http:// or https://).');
-        return false;
-    }
-    
-    clearValidationError(input);
-    return true;
-}
-
-function showFieldError(input, message) {
-    clearValidationError(input);
-    
-    const errorDiv = document.createElement('div');
-    errorDiv.className = 'field-error';
-    errorDiv.textContent = message;
-    errorDiv.style.color = '#dc3545';
-    errorDiv.style.fontSize = '0.875rem';
-    errorDiv.style.marginTop = '0.25rem';
-    
-    input.style.borderColor = '#dc3545';
-    input.parentNode.appendChild(errorDiv);
-}
-
-function clearValidationError(input) {
-    const existingError = input.parentNode.querySelector('.field-error');
-    if (existingError) {
-        existingError.remove();
-    }
-    
-    const existingFormError = document.querySelector('.form-error');
-    if (existingFormError) {
-        existingFormError.remove();
-    }
-    
-    input.style.borderColor = '#e9ecef';
-}
-
-function showFormError(message) {
-    const existingError = document.querySelector('.form-error');
-    if (existingError) {
-        existingError.remove();
-    }
-    
-    const errorDiv = document.createElement('div');
-    errorDiv.className = 'form-error';
-    errorDiv.textContent = message;
-    errorDiv.style.color = '#dc3545';
-    errorDiv.style.backgroundColor = '#f8d7da';
-    errorDiv.style.border = '1px solid #f5c6cb';
-    errorDiv.style.borderRadius = '4px';
-    errorDiv.style.padding = '0.75rem';
-    errorDiv.style.marginBottom = '1rem';
-    errorDiv.style.fontSize = '0.875rem';
-    
-    const form = document.querySelector('.submit-form');
-    form.insertBefore(errorDiv, form.firstChild);
-}
\ No newline at end of file