Rows
row is a Bootstrap row. Declared directly inside a page or tab it lays cm_sections out side by side; declared inside a cm_section it lays fields and form_fields out on one line (it also takes nested_form_sections inside a form).
Quick exampleβ
cm_show page_title: :title do
tab :profile, "" do
row do
cm_section "Details", col_size: 6 do
field :title
field :status, field_type: :badge, badge_class: STATUS_TAG_COLOR
end
cm_section "Log Details", col_size: 6 do
field :created_at, field_type: :date, format: "%d %b, %Y"
end
end
end
end
Optionsβ
row(display_if: nil, html_attrs: nil, &block)
| Name | Type | Default | Description |
|---|---|---|---|
display_if | Proc | nil | Lambda receiving the record; return false to hide. |
html_attrs | Hash | nil | HTML attributes for the row element. |
Recipesβ
Put sections side by sideβ
Each cm_section inside the row takes a col_size in the 12-column grid; sections without col_size share the space evenly:
cm_edit page_title: "Edit Post" do
row do
cm_section "Details", col_size: 8 do
form_field :title, input_type: :string
form_field :body, input_type: :rich_text
end
cm_section "Meta", col_size: 4 do
form_field :status, input_type: :single_select, collection: %w[draft published]
end
end
end
The same works on show pages and inside the main tab, with fields inside the sections.
Lay fields out on one line inside a sectionβ
A row inside a cm_section puts its fields on a single line, inside the section's card:
cm_new page_title: "Add User" do
cm_section "Address" do
row do
form_field :city, input_type: :string
form_field :state, input_type: :string
form_field :pincode, input_type: :string
end
form_field :country, input_type: :single_select, helper_method: :select_options_for_country
end
end
On a show page declare fields in the row the same way β they render side by side, sharing the width evenly:
cm_section "Address" do
row do
field :city
field :state
field :pincode
end
end
Hide a row conditionallyβ
row(display_if: ->(record) { record.name == "John" }, html_attrs: { class: "row-class" }) do
cm_section "Details" do
field :title
end
end
Relatedβ
- Sections:
cm_sectionandnested_form_section - Tabs
- Show/hide rows conditionally