Installation
Add the gem, include the kit, and pick your optional companions.
Add the gem#
In your app's Gemfile.
gem "phlex-forms"
gem "daisyui" # optional — the daisy theme; omit for plain semantic HTML
gem "phlex-reactive" # optional — `live` server-truth validationHard 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:
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.