Getting started

# Installation

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

## Add the gem

In your app's Gemfile.

```ruby
gem "phlex-forms"
gem "phlex-reactive" # optional — `live` server-truth validation
```

Hard dependencies are `phlex ~> 2.0`, `daisyui ~> 2.0`, `activesupport`, `zeitwerk`, and `glyphs`. The daisy theme is the default; switch to the [Plain theme](https://phlex-forms.zoolutions.llc/docs/theming) for unstyled semantic HTML. `phlex-reactive` is **soft**: it only gates the [`live` macro](https://phlex-forms.zoolutions.llc/docs/live-validation).

## Include the kit

phlex-forms exposes its components under the `Forms::` namespace as a [Phlex::Kit](https://www.phlex.fun/kits.html). Include it wherever you render components — typically your base component:

```ruby
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](https://phlex-forms.zoolutions.llc/docs/client-validation) (`validate: true`) and `searchable: true` selects:

```javascript
import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
lazyLoadControllersFrom("phlex_forms/controllers", application)
```

> **Note:** JS peer dependencies: `@hotwired/stimulus` for the validation controllers, and `choices.js` only if you use searchable/multi selects.