Frontend School

Pinterest Pin Creator Form Validation

Machine Coding
medium

Pinterest Pin Creator Form Validation

Medium
React
Frontend
Form Validation
TypeScript
UI

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.

  1. Form Structure: Create a form with the following input fields:
    • Title (text input)
    • Description (textarea)
    • Website URL (text input)
    • A Submit button.
  2. 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.
  3. Error Display: Display clear and user-friendly error messages immediately below the respective input field when validation fails.
  4. 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).
  5. 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.
  6. 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.

Constraints

Constraints & assumptions

  • You must use React and TypeScript.
  • You are not allowed to use external form validation libraries (e.g., Formik, React Hook Form, Zod). All validation logic should be implemented manually.
  • No backend integration is required; validation is purely client-side.
  • Assume basic CSS for layout and error styling is either provided or can be kept minimal to focus on functionality.
  • The target time budget for this problem is approximately 45 minutes.

Out of scope

  • Extensive, pixel-perfect UI styling.
  • Complex global state management beyond the form itself.
  • Server-side validation or API calls.
  • Internationalization (i18n) for error messages.

What interviewers evaluate

  • Correctness and Completeness: How accurately and thoroughly the validation rules are implemented.
  • Code Structure and Readability: The organization, clarity, and maintainability of the React component and its logic.
  • React Fundamentals: Effective use of React state management (e.g., useState) and event handling.
  • User Experience: How well the form provides feedback to the user regarding valid/invalid states and errors.
  • Problem Solving: The approach taken to manage form state, errors, and conditional logic.

Loading editor...