# 📝 PATRONES DE FORMULARIOS ## 1. Form Switch (Checkbox Toggle) ```html
``` **Uso:** Activación/desactivación de features **CSS necesario (Fix WordPress):** ```css /* Eliminar pseudo-elementos de WordPress */ body .form-switch .form-check-input[type="checkbox"]::before, body .form-switch .form-check-input[type="checkbox"]::after { content: none !important; display: none !important; } body .form-switch .form-check-input[type="checkbox"] { background-size: contain !important; background-repeat: no-repeat !important; background-position: left center !important; } body .form-switch .form-check-input[type="checkbox"]:checked { background-position: right center !important; } /* Fix alineación vertical */ .form-check.form-switch { display: flex !important; align-items: center !important; } .form-switch .form-check-input { margin-top: 0 !important; margin-bottom: 0 !important; } .form-switch .form-check-label { line-height: 16px !important; padding-top: 0 !important; margin-top: 0 !important; } ``` --- ## 2. Color Picker ```html
#0E2337
``` **Características:** - Grid de 2 columnas (`col-6`) - Display del valor hex debajo - Width 100% (`.w-100`) **JavaScript:** ```javascript const colorInput = document.getElementById('bgColor'); const colorValue = document.getElementById('bgColorValue'); colorInput.addEventListener('input', function() { colorValue.textContent = this.value.toUpperCase(); updatePreview(); }); ``` --- ## 3. Text Input con Icono ```html
``` **Uso:** Campos de texto cortos (nombres, títulos, etc.) --- ## 4. Textarea con Contador y Progress Bar ```html
``` **JavaScript:** ```javascript const textarea = document.getElementById('messageText'); const counter = document.getElementById('messageTextCount'); const progress = document.getElementById('messageTextProgress'); textarea.addEventListener('input', function() { const length = this.value.length; const maxLength = 250; const percentage = (length / maxLength) * 100; counter.textContent = length; progress.style.width = percentage + '%'; progress.setAttribute('aria-valuenow', length); // Cambiar color según el uso if (percentage > 90) { progress.style.backgroundColor = '#dc3545'; // Rojo } else if (percentage > 75) { progress.style.backgroundColor = '#ffc107'; // Amarillo } else { progress.style.backgroundColor = '#FF8600'; // Orange } updatePreview(); }); ``` --- ## 5. Select Dropdown ```html
``` **Uso:** Opciones predefinidas (tamaños, estilos, etc.) --- ## 6. Badges Informativos ### Badge en Label ```html ``` ### Badge Standalone ```html Opcional Info Requerido ``` --- ## 7. Links de Ayuda ```html Ver: Bootstrap Icons ``` **Características:** - Icono de info - Link orange con hover - Icono de "abrir en nueva ventana" - `target="_blank"` para abrir en pestaña nueva --- ## 8. Grid de Inputs Compactos ### 2 Columnas Iguales ```html
#0E2337
#FFFFFF
``` ### 3 Columnas Desiguales ```html
``` --- ## 9. Campo de URL ```html
Usa rutas relativas (/) o absolutas (https://)
``` --- ## 10. Campos Relacionados (Link) ```html
``` **JavaScript para mostrar/ocultar:** ```javascript const showLink = document.getElementById('showLink'); const linkFields = document.getElementById('linkFields'); showLink.addEventListener('change', function() { linkFields.style.display = this.checked ? 'block' : 'none'; updatePreview(); }); ``` --- ## 11. Validación de Campos ```javascript /** * Valida los campos del formulario */ function validateForm() { let isValid = true; const errors = []; // Validar campo requerido const messageText = document.getElementById('messageText').value.trim(); if (!messageText) { errors.push('El mensaje principal es requerido'); isValid = false; } // Validar longitud if (messageText.length > 250) { errors.push('El mensaje no puede exceder 250 caracteres'); isValid = false; } // Validar URL const linkUrl = document.getElementById('linkUrl').value.trim(); if (linkUrl && !isValidUrl(linkUrl)) { errors.push('La URL no es válida'); isValid = false; } if (!isValid) { alert('⚠️ Errores de validación:\n\n' + errors.join('\n')); } return isValid; } function isValidUrl(string) { // Permitir rutas relativas if (string.startsWith('/')) { return true; } // Validar URLs absolutas try { new URL(string); return true; } catch (_) { return false; } } ``` --- ## Volver al Índice [← Volver al README](README.md)