Overview
The Form component acts as a router that delegates to specific form implementations based on thetype prop. Currently, it only supports location forms that collect complete address information using Google Maps Places API.
Installation
Add the Google Maps script to your HTML:Basic Usage
Props
Form type to render. Currently only supports
"location".Whether Google Maps API is loaded and ready to use. Required for the location form to function properly.
Callback function triggered when the form is submitted or when validation errors occur.
result.data- Complete location object when form is validresult.error- Error message when validation fails
Visual design variant for the form inputs. Defaults to
"primary".Custom placeholder text for the street address input. Defaults to
"Nombre y número de la calle" (Street name and number).Pre-filled location data to initialize the form with.
Custom CSS styles for the form container.
Location Object Structure
The location form returns aLocationProps object with the following structure:
Examples
With Design Variant
With Default Location
With Error Handling
Form Behavior
The location form includes:- Google Maps autocomplete for street address input
- Automatic address parsing from Google Maps Places API
- Additional info input for apartment, floor, etc. (appears after main address is selected)
- Read-only fields for city, postal code, and province (auto-filled from Google Maps)
- Validation that ensures both street name and number are provided
Validation
The form validates that a complete street address (including street number) is provided. If the user doesn’t include a street number, the form will trigger theonSubmit callback with an error:
Notes
- The form uses Spanish language by default for Google Maps Places API
- City, postal code, and province fields are auto-filled and disabled
- The additional info field (apartment, floor) is optional
- The form automatically formats the complete address string