Search documentation

Find a component or a docs page

Form

Building forms with built-in client-side validations.

Usage

Example

Disabled

Custom error message

Backend error

Multiple errors

Without a FormFieldError, a FormField leaves the message to the browser, which shows its native bubble next to the control. If a form mixes fields with and without FormFieldError, focus goes to the first field with a bubble, which can come after the first invalid field.

Checkbox

Fieldset

Horizontal with description

Responsive

Choice card

Separator

Select

Combobox

Rails Integration

RubyUI Form components are plain HTML — they work with any form submission strategy. The recommended approach for Rails apps is to use form_with to generate the action URL and CSRF token, then pass explicit name / id attributes to each RubyUI input so the browser serialises them correctly. Server-side errors can be surfaced by rendering FormFieldError with content from model.errors.full_messages_for(:attr).

Minimal Rails form

# In your Phlex view, call form_with via helpers:
# form_with(url: users_path, method: :post) passes action + CSRF automatically.
#
# You can also set action and the CSRF token manually:
Form(action: helpers.users_path, method: "post", class: "w-2/3 space-y-6") do
  input(type: "hidden", name: "authenticity_token", value: helpers.form_authenticity_token)

  FormField do
    FormFieldLabel(for: "user_email") { "Email" }
    Input(
      type: "email",
      id: "user_email",
      name: "user[email]",
      placeholder: "[email protected]",
      required: true
    )
    FormFieldError()
  end

  Button(type: "submit") { "Continue" }
end

Devise-style login form

# Full sign-in form mirroring Devise session[email] / session[password] params.
# Pass backend errors (e.g. "Invalid email or password") into FormFieldError.
Form(action: helpers.user_session_path, method: "post", class: "space-y-6") do
  input(type: "hidden", name: "authenticity_token", value: helpers.form_authenticity_token)

  FormField do
    FormFieldLabel(for: "session_email") { "Email" }
    Input(
      type: "email",
      id: "session_email",
      name: "session[email]",
      placeholder: "[email protected]",
      autocomplete: "email",
      required: true
    )
    FormFieldError { @error_message }
  end

  FormField do
    FormFieldLabel(for: "session_password") { "Password" }
    Input(
      type: "password",
      id: "session_password",
      name: "session[password]",
      autocomplete: "current-password",
      required: true,
      minlength: "8"
    )
    FormFieldError()
  end

  FormField(orientation: :horizontal) do
    Checkbox(id: "session_remember_me", name: "session[remember_me]", value: "1")
    FormFieldLabel(for: "session_remember_me") { "Remember me" }
  end

  Button(type: "submit", class: "w-full") { "Sign in" }
end

Installation

Components

ComponentBuilt usingSource
FormPhlex
FormDocsPhlex
FormFieldPhlex
FormFieldContentPhlex
FormFieldErrorPhlex
FormFieldGroupPhlex
FormFieldHintPhlex
FormFieldLabelPhlex
FormFieldLegendPhlex
FormFieldSeparatorPhlex
FormFieldSetPhlex
FormFieldTitlePhlex
FormControllerStimulus JS
FormFieldControllerStimulus JS