All inputs support the
caption: argument as a string, which renders explainer text underneath the input and validation message. Caption strings can be anything that responds to
#to_s, meaning HTML-safe strings can be used in cases that need a little bit of markup:
class ExampleForm < ApplicationForm
form do |example_form|
label: "Disco name",
caption: "Enter your <strong>grooviest</strong> name".html_safe
Defining caption templates
In cases where a lot of logic or markup is necessary, or where the caption text is awkward to express in Ruby code, forms may define caption content in separate template files. Caption templates are located in a directory named after the form. For example, if
ExampleForm lives in app/forms/example_form.rb, its caption templates should be created in the
Caption template files must be named after the field they describe. For example, a caption template for the
disco_name field above would live in app/forms/example_form/disco_name_caption.html.erb.
In cases where the
caption: argument and a caption template are provided, the
caption: argument takes precedence.