Phone

Renders an input with label and error messages.

Read more Read less

A Phoenix.HTML.FormField may be passed as argument, which is used to retrieve the input name, id, and values. Otherwise all attributes may be passed explicitly.

Types

This function accepts all HTML input types, considering that:

  • You may also set type="select" to render a <select> tag
  • For live file uploads, see Phoenix.Component.live_file_input/1

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input for more information. Unsupported types, such as hidden and radio, are best written directly in your templates.

Examples

<.input field={@form[:email]} type="email" />
<.input name="my-input" errors={["oh no!"]} />

# Password input with visibility toggle
<.input type="password" name="password" label="Password" />

# The label can be also passed as a custom_label slot (for checkbox, radio, and toggle only)
<.input type="checkbox" name="terms">
  <:custom_label>Accept <.a href="#">terms and conditions</.a></:custom_label>
</.input>

# Password input with help text
<.input type="password" name="password" label="Password">
  <:help>Password must be at least 8 characters long</:help>
</.input>

Accessibility Features

Password Input

  • aria-describedby - Links input with toggle button
  • aria-label - Provides context for the toggle button
  • aria-pressed - Indicates toggle state
  • aria-controls - Associates toggle with input field

Security Features

Password Input

  • Auto-hide password after 5 seconds when revealed
  • autocomplete="current-password" for secure browser password management

For international numbers use country codes, e.g. +44

<.input
  id="phone-single-default"
  label="Phone number"
  name="phone"
  type="phone"
  value={nil}
/>

For international numbers use country codes, e.g. +44

<.input
  id="phone-single-required"
  label="Phone number"
  name="phone"
  type="phone"
  value=""
  required
/>

Phone number is required

<.input
  id="phone-single-with-errors"
  label="Phone number"
  name="phone"
  type="phone"
  value=""
  required
  errors={["Phone number is required"]}
/>

For international numbers use country codes, e.g. +44

<.input
  id="phone-single-with-us-phone-number"
  label="Phone number"
  name="phone"
  type="phone"
  value="+14155552671"
/>

For international numbers use country codes, e.g. +44

<.input
  id="phone-single-with-brazilian-phone-number"
  label="Phone number"
  name="phone"
  type="phone"
  value="555132345678"
/>

For international numbers use country codes, e.g. +44

<.input
  id="phone-single-with-uk-phone-number"
  label="Phone number"
  name="phone"
  type="phone"
  value="+447911123456"
/>

For international numbers use country codes, e.g. +44

<.input
  id="phone-single-with-invalid-phone-number"
  label="Phone number"
  name="phone"
  type="phone"
  value="1234567890"
/>

Custom help message

<.input
  id="phone-single-with-custom-help"
  label="Phone number"
  name="phone"
  type="phone"
  value={nil}
>
  <:help>Custom help message</:help>
</.input>