Form helper
The l_ui_form helper renders a complete form from a record and a field configuration array. It handles labels, inputs, hints, validation errors, and the submit button.
Basic form
Pass a record, an array of field hashes, and a submission URL. Field types are inferred from the model's column types when as: is not specified.
All field types
Use as: to explicitly set the field type. Supported types: :string, :text, :email, :password, :number, :tel, :url, :search, :date, :datetime, :time, :month, :week, :color, :range, :file, :select, :checkbox, and :hidden. The form is automatically rendered as multipart when any field uses :file.
Options
| Option | Type | Description |
|---|---|---|
record |
ActiveRecord | The model instance (first positional argument) |
fields: |
Array | Array of field hashes (see field options below) |
url: |
String | Form submission URL |
method: |
Symbol | HTTP method override (defaults to POST for new records, PATCH for persisted) |
submit: |
String | Submit button text (defaults to "Create" for new records, "Save" for persisted records) |
multipart: |
Boolean | Override multipart encoding. Defaults to auto-detection (true when any field is :file). Pass true or false to force. |
Need more control? Override the partial by creating app/views/layered/ui/managed_resource/_form.html.erb in your host app, or write the form directly with form_with and reuse layered_ui/shared/form_errors, layered_ui/shared/label, and layered_ui/shared/field_error.
Field options
| Option | Type | Description |
|---|---|---|
attribute: |
Symbol | Model attribute name (required) |
as: |
Symbol | Field type (:string, :text, :email, :password, :number, :tel, :url, :search, :date, :datetime, :time, :month, :week, :color, :range, :file, :select, :checkbox, :hidden). Inferred from column type when omitted. |
label: |
String | Custom label text (defaults to humanised attribute name) |
required: |
Boolean | Marks field as required with a visual indicator (defaults to false) |
hint: |
String | Help text displayed below the input |
placeholder: |
String | Placeholder text for the input |
collection: |
Array / Proc | Options for :select fields. Array of [label, value] pairs or a callable. |
prompt: |
String | Prompt text for :select fields (e.g. "Choose an author"). Shown as the first option; only selectable when no value is set. Setting prompt: suppresses the default blank option. |
include_blank: |
Boolean / String | For :select fields. Defaults to true. Pass a string to use it as the blank option's label, or false to omit the blank option entirely. |