Overview
The data validation API provides functions to validate user input, ensure data integrity, and display error messages to users.validarFormulariosVehiculos()
Validates that all vehicle forms have complete and valid data before processing. Source:script.js:167-184
Parameters
This function takes no parameters. It validates based on the globalnumeroAutos variable.
Returns
boolean - Returns true if all forms are valid, false otherwise
Validation Checks
For each vehicle (1 tonumeroAutos):
- Motorization Selection: Verifies that a motorization radio button is selected
- ITV Status Selection: Verifies that an ITV status radio button is selected
If validation fails,
mostrarError() is automatically called with a specific error message indicating which vehicle and field needs attention.Example Implementation
Usage
mostrarError()
Displays a styled error message to the user in a fixed notification. Source:script.js:381-464
Parameters
The error message to display to the user
Returns
void - Does not return a value
Side Effects
- Creates a fixed-position error alert in the top-right corner
- Removes any existing error alerts before showing the new one
- Automatically dismisses after 5 seconds
- Injects CSS styles if not already present
- Adds close button for manual dismissal
Alert Features
- Position: Fixed top-right (20px from edges)
- Animation: Slides in from the right
- Auto-dismiss: 5 seconds
- Manual close: Click the × button
- Styling: Red gradient background with warning icon
Example Implementation
Usage Examples
inicializarEventos()
Sets up real-time validation and input enhancement for form fields. Source:script.js:487-516
Parameters
This function takes no parameters.Returns
void - Does not return a value
Event Listeners
This function adds the following event listeners:1. Number of Vehicles Input Validation
- Event:
input - Field:
#nAutos - Validation:
- Maximum value: 50
- Minimum value: 0
- Shows error if exceeded
2. Numeric Keypress Filter
- Event:
keypress - Field:
#nAutos - Behavior: Only allows numeric input (0-9)
3. Text Capitalization
- Event:
input - Fields:
#nombre,#apellidos,#razonSocial - Behavior: Automatically capitalizes first letter
Example Implementation
Initialization
This function is automatically called on
DOMContentLoaded to ensure all validation is active when the page loads.Validation Constants
Vehicle Number Limits
- Minimum: 1 vehicle
- Maximum: 50 vehicles
- Type: Integer only
Text Field Requirements
- nombre: Required, auto-capitalized
- apellidos: Required, auto-capitalized
- razonSocial: Required, auto-capitalized
Vehicle Form Requirements
For each vehicle:- Motorization: Required (one of: Diesel, Gasolina, Híbrido, Eléctrico)
- ITV Status: Required (one of: Aprobado, No Aprobado)
- Observaciones: Optional, max 250 characters
Error Messages
| Validation Error | Message |
|---|---|
| Missing client fields | ”Por favor, complete todos los campos obligatorios.” |
| Invalid vehicle number | ”Por favor, ingrese un número válido de vehículos (1-50).” |
| Vehicle count exceeded | ”El número máximo de vehículos es 50.” |
| Missing motorization | ”Por favor, seleccione la motorización para el vehículo .” |
| Missing ITV status | ”Por favor, seleccione el estado ITV para el vehículo .” |
| Calculation error | ”Ha ocurrido un error al procesar los datos. Por favor, verifique la información ingresada.” |
Related Functions
- Form Generation - Generate dynamic forms
- Calculation Engine - Process validated data
- Export Functions - Export validated results