Form Components
Tienda ETCA includes three main form components for user interaction and product management. These forms handle contact submissions, product creation, and product editing.Overview
Formulario
Contact form for user inquiries
FormularioProducto
Add new products to catalog
FormularioEdicion
Edit existing product details
Formulario (Contact Form)
A simple contact form for user inquiries and messages. File:src/components/Formulario.jsx
Overview
The contact form collects basic user information including name, email, and message. It uses Bootstrap styling for a clean, responsive design.Component Structure
Formulario.jsx
Features
Form Fields
Form Fields
Three input fields arranged in a responsive grid:
- Nombre - User’s name (text input, required)
- Correo - Email address (email input, required)
- Mensaje - User’s message (text input, required)
form-control class for consistent styling.State Management
State Management
Uses React Each field’s value is controlled by state and updates on change.
useState for controlled form inputs:Form Submission
Form Submission
Handles form submission with basic alert:
Validation
Validation
Uses HTML5 validation:
- All fields are
required - Email field uses
type="email"for format validation - Browser-native validation messages
Layout
The form uses Bootstrap’s grid system:- Three columns on medium screens and above (
col-md-4) - Stacks vertically on smaller screens
- Submit button aligned to the right
Usage Example
In Contacto Layout
FormularioProducto (Add Product Form)
Modal form for adding new products to the catalog with validation. File:src/components/FormularioProducto.jsx
Overview
A modal-based form that allows administrators to add new products. Includes comprehensive validation and error handling.Component Structure
FormularioProducto.jsx
Props
Callback function to handle product creation. Receives the product object as a parameter.
Callback function to close the modal.
Features
Form Fields
Form Fields
Three fields for new product data:
| Field | Type | Validation |
|---|---|---|
| Nombre | Text | Required, non-empty |
| Precio | Number | Required, must be > 0 |
| Descripción | Textarea | Required, min 10 characters |
Validation
Validation
Custom validation with error messages:Validation Rules:
- Name cannot be empty
- Price must be greater than 0
- Description must be at least 10 characters
Error Display
Error Display
Dynamic error feedback:
- Error messages appear below invalid fields
- Uses Bootstrap’s
is-invalidclass for styling - Real-time validation on submit
- Clear error messages in Spanish
Modal Behavior
Modal Behavior
Modal overlay functionality:
- Appears over main content
- Close button in top-right corner
- Backdrop overlay (
.modal-overlay) - Form resets on successful submission
- Modal closes after submission
State Management
Usage Example
In Admin Layout
FormularioEdicion (Edit Product Form)
Modal form for editing existing product information. File:src/components/FormularioEdicion.jsx
Overview
A comprehensive form for editing product details, including all product attributes. Displayed in a modal overlay.Component Structure
FormularioEdicion.jsx (excerpt)
Props
Product object to edit. Contains all product properties:
Callback function to handle product update. Receives updated product object.
Callback function to close the modal.
Form Fields
- Product Info
- Media & Category
- Description
Basic Product Information
- ID - Read-only product identifier
- Nombre - Product name (text, required)
- Precio - Product price (number, required, min: 0)
- Stock - Available stock (number, required)
Complete Field List
| Field | Type | Attributes | Required |
|---|---|---|---|
| ID | number | readonly | ✓ |
| Nombre | text | - | ✓ |
| Precio | number | min=“0” | ✓ |
| Stock | number | - | ✓ |
| Imagen | text | URL | ✓ |
| Categoría | text | - | ✓ |
| Descripción | textarea | rows=“4” | - |
Features
Dynamic Data Loading
Dynamic Data Loading
Uses This ensures the form always displays the latest product data.
useEffect to update form when selected product changes:Controlled Inputs
Controlled Inputs
All form fields are controlled components:Default empty strings prevent uncontrolled input warnings.
Form Submission
Form Submission
Handles update and closes modal:
Usage Example
In Admin Layout
Styling
All form components use Bootstrap for base styling, with custom CSS for modal behavior.CSS Files
Form Validation Summary
Formulario
HTML5 Validation
- Required fields
- Email format
- Browser-native messages
FormularioProducto
Custom Validation
- Name: non-empty
- Price: greater than 0
- Description: min 10 chars
- Spanish error messages
FormularioEdicion
Required Fields
- All fields required except descripción
- Number validation for precio/stock
- No custom validation messages
Best Practices
Form SubmissionAll forms use
e.preventDefault() to prevent default browser form submission. This allows for custom handling of form data.Related Documentation
Components Overview
See all available components
Admin Context
Learn about product management state