Installation
Add the gem, include the kit, and pick your optional companion.
Add the gem#
In your app's Gemfile.
gem "phlex-forms"
gem "phlex-reactive" # optional — `live` server-truth validationHard dependencies are phlex ~> 2.0, daisyui ~> 2.0, activesupport, zeitwerk, and glyphs. The daisy theme is the default; switch to the Plain theme for unstyled semantic HTML. phlex-reactive is soft: it 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:
class ApplicationComponent < Phlex::HTML
include Forms
endNow 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 toI18n.load_pathso your app overrides any key, - the phlex-reactive param type the
liveaction 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:
import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
lazyLoadControllersFrom("phlex_forms/controllers", application)@hotwired/stimulus for the validation controllers, and choices.js only if you use searchable/multi selects.