Class: UiBibz::Ui::Core::Forms::Choices::ChoiceGroup
- Inherits:
-
Buttons::ButtonGroup
- Object
- Base
- Component
- Buttons::ButtonGroup
- UiBibz::Ui::Core::Forms::Choices::ChoiceGroup
- Includes:
- UiBibz::Ui::Concerns::HtmlConcern
- Defined in:
- lib/ui_bibz/ui/core/forms/choices/choice_group.rb
Overview
Create a choice group
This element is an extend of UiBibz::Ui::Core::Forms::Choices::ButtonGroup
Attributes
-
content
- Content of element -
options
- Options of element -
html_options
- Html Options of element
Options
You can add HTML attributes using the html_options
. You can pass arguments in options attribute:
-
type
- Symbol (:checkbox
,:radio
) -
status
- status of element with symbol value: (:primary
,:secondary
,:info
,:warning
,:danger
) -
size
(:xs
,:sm
,:lg
) -
outline
- Boolean -
state
- Symbol (:active
, +:disabled)
Signatures
UiBibz::Ui::Core::Forms::Choices::ChoiceGroup.new(content, = nil, = nil)
UiBibz::Ui::Core::Forms::Choices::ChoiceGroup.new( = nil, = nil) do
content
end
Examples
UiBibz::Ui::Core::Forms::Choices::ChoiceGroup.new({ status: primary }, { class: 'lable-class'}) do |cg|
cg.choice 'Choice 1'
cg.choice 'Choice 2'
end.render
Helper
ui_choice_group( = {}, = {}) do |cg|
cg.choice content, ,
cg.choice content, ,
end
Constant Summary
Constants inherited from Component
Component::BREAKPOINTS, Component::SIZES, Component::STATUSES
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#required_fields ⇒ Object
readonly
Returns the value of attribute required_fields.
Attributes inherited from Component
#content, #html_options, #options
Attributes inherited from Base
Instance Method Summary collapse
- #choice(content = nil, opts = nil, html_options = nil, &block) ⇒ Object
-
#initialize(content = nil, options = nil, html_options = nil, &block) ⇒ ChoiceGroup
constructor
See UiBibz::Ui::Core::Forms::Choices::Button.initialize.
- #input(attribute_name, options = {}, &block) ⇒ Object
Methods inherited from Buttons::ButtonGroup
#button, #button_link, #choice_group, #dropdown, #html, #pre_render, #split_dropdown
Methods inherited from Component
#pre_render, #render, #tapped?
Methods included from PopoverExtension
#popover_data_html, #tooltip_data_html
Methods included from GlyphExtension
#generate_glyph, #glyph_and_content_html
Methods included from KlassExtension
#exclude_classes, #exclude_classes_in_html_options, #join_classes, #status
Methods inherited from Base
#generate_id, #i18n_set?, #inject_url
Constructor Details
#initialize(content = nil, options = nil, html_options = nil, &block) ⇒ ChoiceGroup
See UiBibz::Ui::Core::Forms::Choices::Button.initialize
55 56 57 58 59 60 61 |
# File 'lib/ui_bibz/ui/core/forms/choices/choice_group.rb', line 55 def initialize(content = nil, = nil, = nil, &block) super @items = [] @errors = [] @required_fields = [] @radio_name = @options[:name] || generate_id('choice') end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
51 52 53 |
# File 'lib/ui_bibz/ui/core/forms/choices/choice_group.rb', line 51 def errors @errors end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
51 52 53 |
# File 'lib/ui_bibz/ui/core/forms/choices/choice_group.rb', line 51 def items @items end |
#required_fields ⇒ Object (readonly)
Returns the value of attribute required_fields.
51 52 53 |
# File 'lib/ui_bibz/ui/core/forms/choices/choice_group.rb', line 51 def required_fields @required_fields end |
Instance Method Details
#choice(content = nil, opts = nil, html_options = nil, &block) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ui_bibz/ui/core/forms/choices/choice_group.rb', line 63 def choice(content = nil, opts = nil, = nil, &block) if block.nil? opts = @options.merge(opts || {}) else content = @options.merge(content || {}) end opts = opts.merge(name: @radio_name) if opts[:type] == :radio @items << Choice.new(content, opts, , &block) end |
#input(attribute_name, options = {}, &block) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/ui_bibz/ui/core/forms/choices/choice_group.rb', line 75 def input(attribute_name, = {}, &block) = .merge(old_label: [:label], label: false, wrapper: false, error: false) = .merge(name: @radio_name, type: :radio) if @options[:type] == :radio @items << @options[:form].input(attribute_name, , &block) obj = @options[:form].object @errors << obj.errors[attribute_name] unless obj.errors[attribute_name].empty? @required_fields << (obj._validators[attribute_name].try(:first).class.to_s == 'ActiveRecord::Validations::PresenceValidator') end |