Getting started

Installation

Add the gem, include the kit, and pick your optional companions.

Add the gem#

In your app's Gemfile.

Gemfile
gem "phlex-forms"
gem "daisyui"        # optional — the daisy theme; omit for plain semantic HTML
gem "phlex-reactive" # optional — `live` server-truth validation

Hard dependencies are just phlex (~> 2.0), activesupport, zeitwerk, and glyphs. Both companions are soft: with daisyui loaded the daisy theme is the default; without it the Plain theme takes over. phlex-reactive only gates the live macro.

Include the kit#

phlex-forms exposes its components under the Forms:: namespace as a Phlex::Kit. Include it wherever you render components — typically your base component:

app/components/application_component.rb
class ApplicationComponent < Phlex::HTML
  include Forms
end

Now Form(...), Submit(...), and every other Forms::* component are available as bare kit helpers, and Forms::Base is ready to subclass.

Under Rails#

The gem ships an optional Rails engine (loaded only when Rails::Engine is defined) that wires up:

  • the bundled Stimulus controllers via importmap + the asset load path,
  • the default locale files (en/sv/de), prepended to I18n.load_path so your app overrides any key,
  • the phlex-reactive param type the live action schema needs.

Outside Rails, phlex-forms stays a plain Phlex library — the engine never loads.

Stimulus controllers (optional)#

Only needed for client-side validation (validate: true) and searchable: true selects:

app/javascript/controllers/index.js
import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
lazyLoadControllersFrom("phlex_forms/controllers", application)
JS peer dependencies: @hotwired/stimulus for the validation controllers, and choices.js only if you use searchable/multi selects.