Overview
At Pinterest, creating and sharing inspiring content is at the core of our user experience. A smooth and intuitive Pin creation process is crucial for user engagement. This problem focuses on building a robust client-side form validation system for a simplified Pin creation form, ensuring that users provide valid and complete information before publishing their ideas.
Your task is to implement the front-end logic for a Pin creation form, focusing specifically on real-time and submission-time validation, providing clear feedback to the user.
What you need to do / Task
Your primary goal is to implement a functional Pin creation form with client-side validation. You will be provided with a basic React component structure and minimal styling.
- Form Structure: Create a form with the following input fields:
Title (text input)
Description (textarea)
Website URL (text input)
- A
Submit button.
- Client-Side Validation: Implement validation rules for each field:
- Title:
- Required: Must not be empty.
- Length: Must be between 5 and 100 characters (inclusive).
- Description:
- Length: Optional, but if provided, must not exceed 500 characters.
- Website URL:
- Format: Optional, but if provided, must be a valid URL (e.g., start with
http:// or https://, and have a domain). A simple regex check or new URL() approach is acceptable.
- Error Display: Display clear and user-friendly error messages immediately below the respective input field when validation fails.
- Submit Button State: The
Submit button must be disabled if the form is in an invalid state (i.e., any required field is invalid or any field has an active validation error).
- Validation Triggers:
- Display errors for a field when the user blurs out of it (
onBlur).
- Display all active errors when the
Submit button is clicked, even if fields haven't been blurred yet.
- Clear errors for a field as the user types and fixes the issue.
- Form Submission: On successful submission (when all fields are valid), log the form data to the console and clear the form fields.
UI/UX expectations
- Layout: Arrange form fields vertically with clear labels above each input.
- Error Messages: Error messages should be styled distinctly (e.g., red text) and placed directly below the corresponding input field.
- Interactions: Input fields should update their visual state (e.g., border color) to indicate an error, if desired. The submit button should clearly indicate its disabled state.
- Accessibility: Ensure form fields have associated labels (
for/id attributes). Consider adding aria-describedby for error messages if time permits.
Acceptance criteria
- The form renders with Title, Description, Website URL inputs, and a Submit button.
- The Title field is correctly validated as required and between 5-100 characters.
- The Description field is correctly validated for a maximum length of 500 characters.
- The Website URL field is correctly validated for a valid URL format when provided.
- Error messages appear below fields on
onBlur and onSubmit for invalid inputs.
- Error messages disappear as inputs become valid.
- The Submit button is disabled when the form is invalid and enabled when all fields are valid.
- On successful submission, form data is logged to the console, and fields are reset.