Spree::Admin::FormBuilder that extends Rails’ standard FormBuilder with additional helper methods designed specifically for the admin interface. This form builder ensures consistent styling, error handling, and behavior across all admin forms.
Using the FormBuilder
The FormBuilder is automatically available in admin forms when usingform_with:
Common Options
All FormBuilder methods support these common options:| Option | Type | Description |
|---|---|---|
:label | String or false | Custom label text, or false to hide the label entirely |
:required | Boolean | Adds a red asterisk (*) indicator next to the label |
:help | String | Help text displayed below the field |
:help_bubble | String | Tooltip text displayed in a help bubble icon next to the label |
:class | String | Additional CSS classes for the input element |
Text Input Methods
spree_text_field
Creates a text input field with Spree styling.- All standard Rails
text_fieldoptions - All common FormBuilder options
spree_number_field
Creates a number input field with Spree styling.- All standard Rails
number_fieldoptions (:min,:max,:step) - All common FormBuilder options
spree_money_field
Creates a locale-aware money/currency input field with automatic formatting. This field displays amounts in the currency’s locale format (e.g.,1.234,56 for EUR, 1,234.56 for USD) and normalizes values to standard decimal format before form submission.
| Option | Type | Description |
|---|---|---|
:currency | String | Currency code (e.g., 'USD', 'EUR', 'PLN'). Used to determine decimal/thousands separators and display the currency symbol |
:value | BigDecimal, Float, String | Override the displayed value (will be formatted for the currency’s locale) |
:prepend | String | Text to prepend before the input field |
:append | String | Text to append after the input field (defaults to currency symbol when :currency is provided) |
:disabled | Boolean | Disable the input field |
:label, :required, :help, :help_bubble) are also supported.
Features:
- Locale-aware display: Values are displayed using the currency’s decimal mark (e.g., comma for EUR/PLN, dot for USD)
- Automatic normalization: Values are converted to standard decimal format (with
.as decimal separator) before form submission - Currency symbol: Automatically appends the currency symbol when
:currencyoption is provided - Mobile-friendly: Uses
inputmode="decimal"for appropriate mobile keyboard - Auto-formatting: Values are reformatted on blur to ensure consistent display
The money field uses a Stimulus controller (
money-field) that handles formatting and normalization automatically. The decimal and thousands separators are determined by the currency’s ISO standard configuration.spree_email_field
Creates an email input field with Spree styling and HTML5 validation.- All standard Rails
email_fieldoptions - All common FormBuilder options
Date and Time Methods
spree_date_field
Creates a date picker input field.- All standard Rails
date_fieldoptions (:min,:max) - All common FormBuilder options
spree_datetime_field
Creates a datetime picker input field.- All standard Rails
datetime_fieldoptions - All common FormBuilder options
Text Area Methods
spree_text_area
Creates a textarea with auto-grow functionality (expands as you type).:rows- Number of visible rows (default: 5):data- Data attributes (default includes auto-grow Stimulus controller)- All standard Rails
text_areaoptions - All common FormBuilder options
textarea-autogrow Stimulus controller.
spree_rich_text_area
Creates a rich text editor using Trix.- WYSIWYG editing
- Basic formatting (bold, italic, lists, links)
- File attachments via Active Storage
- All common FormBuilder options
Select Methods
spree_select
Creates a select dropdown field.method- The attribute namechoices- Array of optionsoptions- Select options (:include_blank,:prompt,:autocomplete)html_options- HTML attributes (:class,:data,:disabled)
:autocomplete- Enables searchable dropdown with autocomplete functionality- All standard Rails
selectoptions - All common FormBuilder options
spree_collection_select
Creates a select dropdown from a collection of objects.method- The attribute namecollection- ActiveRecord collection or array of objectsvalue_method- Method to call for option value (e.g.,:id)text_method- Method to call for option text (e.g.,:name)options- Select options (:include_blank,:autocomplete)html_options- HTML attributes
:autocomplete- Enables searchable dropdown- All standard Rails
collection_selectoptions - All common FormBuilder options
Checkbox and Radio Methods
spree_check_box
Creates a styled checkbox with custom controls.- All standard Rails
check_boxoptions - All common FormBuilder options
spree_radio_button
Creates a styled radio button with custom controls.method- The attribute nametag_value- The value for this radio optionoptions- Options hash (must include:id)
:id- Required HTML ID for the radio button- All standard Rails
radio_buttonoptions - All common FormBuilder options
File Upload Methods
spree_file_field
Creates a file upload field with image preview, drag-and-drop support, and optional cropping functionality.| Option | Type | Default | Description |
|---|---|---|---|
:width | Integer | 300 | Width of the image preview in pixels |
:height | Integer | 300 | Height of the image preview in pixels |
:crop | Boolean | false | Enable image cropping with recommended size indicator |
:auto_submit | Boolean | false | Automatically submit form when file is selected |
:can_delete | Boolean | true | Show delete button for removing uploaded image |
:css | String | '' | Additional CSS classes for the upload placeholder area |
:allowed_file_types | Array | Image types | Specify the allowed file types |
:label, :required, :help, :help_bubble) are also supported.
Features:
- Drag-and-drop file upload
- Image preview after upload
- Optional image cropping with size recommendations
- Delete button to remove uploaded files
- Uses Active Storage direct upload
Complete Form Example
Here’s a complete example showing various FormBuilder methods:Error Handling
All FormBuilder methods automatically display validation errors below the field when present:@product.errors[:name] contains errors, they will be displayed automatically in red text below the input field.
Internationalization
Labels are automatically translated using Rails I18n. The FormBuilder looks for translations in this order:- Custom label passed via
:labeloption spree.{attribute_name}keyactiverecord.attributes.spree/{model_name}.{attribute_name}key
Styling and CSS Classes
All FormBuilder methods use consistent styling:- Form groups: Each field is wrapped in a
.form-groupdiv - Input classes: Text inputs use
.form-controlclass - Select classes: Dropdowns use
.custom-selectclass - Checkboxes/Radios: Use
.custom-control,.custom-checkbox,.custom-radioclasses
:class option:
Best Practices
Use the Spree FormBuilder methods instead of standard Rails helpers for consistent styling
Add
:required option to required fields for visual indicationUse
:help text to provide guidance for complex fieldsUse
:help_bubble for additional context without cluttering the formEnable autocomplete on selects with many options (> 20 items)

