This chapter describes form building and validation in the Folio Rails Engine, highlighting the built-in custom inputs that ship with Folio and explaining how to add new ones.
Folio provides flexible tools for building and validating forms, both in the admin console and in public-facing features. A set of custom Simple Form inputs ships with the engine to handle common use-cases (e.g., rich-text editors, tag selectors, phone numbers).
The engine includes the following input classes (see app/inputs/):
| Input class | Purpose |
|---|---|
RedactorInput |
Rich-text editor using Redactor |
TagsInput |
Tag selector with autocomplete |
UrlJsonInput |
Array of links stored as JSON |
DateRangeInput |
Two-field date range picker |
PhoneInput |
Phone number input with formatting |
You can use these inputs directly in your simple_form_for blocks:
= f.input :content, as: :redactor
= f.input :tags, as: :tagsFolio does not currently provide a generator for new inputs. To add a custom input:
- Create a new class in
app/inputs/, inheriting fromSimpleForm::Inputs::Baseor another existing input. - Implement the
inputmethod and any helpers. - Add related JavaScript or CSS if needed - utilize
register_stimulusfor JS behavior. - Document usage in your project.
You can copy one of the built-in inputs as a starting point.
- Admin forms are built with Rails helpers and the custom inputs above.
- Model validations ensure data integrity; additional validation logic can be placed in form objects or service layers.
- For complex workflows you can create form objects (POROs) that encapsulate validation and persistence logic.
- Reuse and adapt the built-in inputs where possible.
- Keep validation logic in the model or a dedicated form object.
- Use namespaced CSS/JS for custom inputs to avoid conflicts.
- Document any custom input's expected data format.
For more details, see the individual chapters linked above. This forms overview will be updated as the documentation evolves.