field(label, hint: nil, error: nil) do
# the control: text_field_tag, f.select… with class "tr-input" / "tr-select"
end
search_input(name: :q, value: nil, placeholder: "Buscar", label: nil, **html)
field wraps any control with its label and a hint or error. Style the control with tr-input, tr-select or tr-check (also through form builders: f.text_field :name, class: "tr-input"). search_input is the search box with its icon; in a page header's filters row it grows to fill the row.
<%= stack(style: "max-width: 420px") do %>
<%= search_input name: :q, placeholder: "Buscar por número, chave, nome ou CNPJ" %>
<%= field "Nome da empresa" do %>
<%= text_field_tag :name, "Empresa Exemplo Ltda", class: "tr-input" %>
<% end %>
<%= field "Ambiente", hint: "Notas de homologação não têm validade jurídica." do %>
<%= select_tag :environment, options_for_select(%w[Produção Homologação]), class: "tr-select" %>
<% end %>
<%= field "E-mail", error: "Informe um e-mail válido, como nome@exemplo.com." do %>
<%= email_field_tag :email, "nome@", class: "tr-input", aria: { invalid: true } %>
<% end %>
<%= cluster(gap: "20px") do %>
<label class="tr-cluster"><%= check_box_tag :canceled, "1", true, class: "tr-check" %> Mostrar canceladas</label>
<label class="tr-cluster"><%= radio_button_tag :kind, "issued", true, class: "tr-check" %> Emitidas</label>
<label class="tr-cluster"><%= radio_button_tag :kind, "received", false, class: "tr-check" %> Recebidas</label>
<% end %>
<% end %>
Read-only and disabled
Read-only (readonly: true) keeps a white field with a lighter border: the value reads and copies normally but cannot change. Disabled (disabled: true) is greyed out with muted text and a not-allowed cursor, and its label turns muted too. Say in the hint why a field is disabled and what unlocks it.
<%= stack(style: "max-width: 420px") do %>
<%= field "CNPJ", hint: "Somente leitura: dá para selecionar e copiar, não para editar." do %>
<%= text_field_tag :doc, "12.345.678/0001-90", class: "tr-input", readonly: true %>
<% end %>
<%= field "Razão social", hint: "Desativado: liberado depois de validar o certificado." do %>
<%= text_field_tag :name, "Empresa Exemplo Ltda", class: "tr-input", disabled: true %>
<% end %>
<%= field "Município" do %>
<%= select_tag :city, options_for_select([ "São Paulo/SP" ]), class: "tr-select", disabled: true %>
<% end %>
<%= field "Observação" do %>
<%= text_field_tag :note, nil, class: "tr-input", placeholder: "Sem observações", disabled: true %>
<% end %>
<%= cluster(gap: "20px") do %>
<label class="tr-cluster" style="color: var(--muted)"><%= check_box_tag :locked, "1", true, class: "tr-check", disabled: true %> Marcado e desativado</label>
<label class="tr-cluster" style="color: var(--muted)"><%= radio_button_tag :kind_locked, "x", false, class: "tr-check", disabled: true %> Opção desativada</label>
<% end %>
<%= toggle_switch "settings[locked]", label: "Switch desativado", checked: true, disabled: true %>
<%= cluster do %>
<%= button "Salvar", variant: :primary, disabled: true %>
<%= button "Cancelar", disabled: true %>
<% end %>
<% end %>
Options
| Option | What it does |
|---|---|
label | Text before the control |
hint | Muted help line under the control |
error | Error line under the control; also set aria-invalid on the control |