Choice group(ui_choice_group)
UiBibz::Ui::Core::Forms::Choices::ChoiceGroup
Allow use checkbox or radio inputs throught button element.
Usage
This component is an extension of component element. A Ui Bibz component consists of 3 arguments:
ui_choice_group do |bc|
# by variable
bc.choice content, options, html_options
# or by block
bc.choice options, html_options do
content
end
end
Examples
Some examples explain how to use the options present in the component.Checkbox buttons
ui_choice_group do |bc|
bc.choice "Checkbox 1"
bc.choice "Checkbox 2", state: :active
end
<div data-bs-toggle="buttons" class="btn-group btn-group-toggle" >
<label class="btn-secondary btn"><input type="checkbox" autocomplete="off">Checkbox 1</label>
<label class="active btn-secondary btn"><input type="checkbox" autocomplete="off" checked="checked">Checkbox 2</label>
</div>
Button choice blocks
Button choice has on block type:
- choice (inherit of button)
Checkbox buttons options
ui_choice_group size: :sm, outline: true, status: :success do |bc|
bc.choice "Checkbox 1"
bc.choice "Checkbox 2", state: :active, glyph: "gem"
end
<div data-bs-toggle="buttons" class="btn-group btn-group-sm button-choice btn-group-toggle">
<label class="btn-outline-success btn btn-sm checkbox">
<input type="checkbox" autocomplete="off">Checkbox 1
</label>
<label class="active btn-outline-success btn btn-sm checkbox" aria-pressed="true">
<input type="checkbox" autocomplete="off" checked="checked">
<i class="glyph fa fa-gem"></i>Checkbox 2
</label>
</div>
Radio button
ui_choice_group type: :radio do |bc|
bc.choice "Radio 1"
bc.choice "Radio 2"
end
<div data-bs-toggle="buttons" class="btn-group btn-group-toggle" role="group">
<label class="btn-primary btn"><input type="radio" autocomplete="off">Radio 1</label>
<label class="active btn-primary btn"><input type="radio" autocomplete="off" checked="checked">Radio 2</label>
</div>
Radio buttons options
ui_choice_group size: :lg, outline: true, type: :radio do |bc|
bc.choice "Radio 1", status: :danger, glyph: "gem"
bc.choice "Radio 2", status: :danger
end
<div data-bs-toggle="buttons" class="btn-group btn-group-toggle" role="group">
<label class="btn-danger-outline btn btn-lg"><input type="radio" autocomplete="off">Radio 1</label>
<label class="active btn-danger-outline btn btn-lg"><input type="radio" autocomplete="off" checked="checked">Radio 2</label>
</div>
Radio buttons options
ui_choice_group size: :lg, status: :primary, outline: true, type: :radio do |bc|
bc.choice "Radio 1", glyph: "gem", state: :active, text: false
bc.choice "Radio 2", status: :danger
bc.choice "Radio 3"
bc.choice "Radio 4", status: :danger
end
<div data-bs-toggle="buttons" class="btn-group btn-group-toggle" role="group">
<label class="btn-danger-outline btn btn-lg"><input type="radio" autocomplete="off">Radio 1</label>
<label class="active btn-danger-outline btn btn-lg"><input type="radio" autocomplete="off" checked="checked">Radio 2</label>
</div>
Simple form
Ui Bibz is compatible with simple form.
You can use defaults inputs of Simple Form and defaults inputs of Ui Bibz like ui_choice_field
. You can use Simple Form input options and Ui Bibz ui_choice_field options.
ui_bibz_form_for(@user) do |f|
...
f.ui_choice_group do |cg|
cg.input :active, as: :ui_choice_field
cg.input :active, as: :ui_choice_field, label: "Checkbox 2"
end
f.ui_choice_group type: :radio do |cg|
cg.input :active, as: :ui_choice_field, label: "Radio 1"
cg.input :active, as: :ui_choice_field, label: "Radio 2"
end
...
end