Skip to main content

Variety of the Input in Form

What Are Controlled Components?

In React, we like to keep everything in check. A "controlled component" means React is in control of what's happening in the form. It helps us manage things more easily.


Multiple kinds of input

Let's make our form more interesting! We can add variety of input type to our form to make our user experience better.

Here are some commonly used input types in React forms:

  1. Text Input (<input type="text">):
    • Used for general text input.
    • Suitable for short to medium-length text, such as names and addresses.
  1. Password Input (<input type="password">):
    • Designed for securely capturing passwords.
    • Characters are typically masked for privacy.
  1. Email Input (<input type="email">):
    • Specifically designed for capturing email addresses.
    • Includes built-in browser validation for email format.
  1. Number Input (<input type="number">):
    • Used for numeric input, such as age or quantity.
    • May include up/down arrows for easy value adjustment. 
  1. Checkbox (<input type="checkbox">):
    • Allows users to select one or more options from a list.
    • Suitable for binary choices or multiple selections.
  1. Radio (<input type="radio">):
    • Used when users need to select a single option from a list.
    • Grouped together using the same name attribute.
  1. Textarea (<textarea>):
    • Used for multi-line text input, suitable for longer messages or comments.
  1. File Input (<input type="file">):
    • Enables users to upload files.
    • Typically used for images, documents, or other file types.
  1. Date Input (<input type="date">), Time Input (<input type="time">), and DateTime Input (<input type="datetime-local">):
    • Used for capturing dates, times, or both.

Here's the example of variety form type

1706260655230.png

You can implement it likes usual by make the state to store data and have a handle function to handle events likes form that you've seen in previous page.

FormExample2.png