class UiBibz::Ui::Core::Forms::Choices::ChoiceGroup
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, options = nil, html_options = nil) UiBibz::Ui::Core::Forms::Choices::ChoiceGroup.new(options = nil, html_options = 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(options = {}, html_options = {}) do |cg| cg.choice content, options, html_options cg.choice content, options, html_options end
Attributes
errors[R]
items[R]
required_fields[R]
Public Class Methods
new(content = nil, options = nil, html_options = nil, &block)
click to toggle source
See UiBibz::Ui::Core::Forms::Choices::Button.initialize
Calls superclass method
UiBibz::Ui::Core::Forms::Buttons::ButtonGroup::new
# File lib/ui_bibz/ui/core/forms/choices/choice_group.rb, line 55 def initialize(content = nil, options = nil, html_options = nil, &block) super @items = [] @errors = [] @required_fields = [] @radio_name = @options[:name] || generate_id('choice') end
Public Instance Methods
choice(content = nil, opts = nil, html_options = nil, &block)
click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/choice_group.rb, line 63 def choice(content = nil, opts = nil, html_options = 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, html_options, &block) end
input(attribute_name, options = {}, &block)
click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/choice_group.rb, line 75 def input(attribute_name, options = {}, &block) new_options = options.merge(old_label: options[:label], label: false, wrapper: false, error: false) new_options = new_options.merge(name: @radio_name, type: :radio) if @options[:type] == :radio @items << @options[:form].input(attribute_name, new_options, &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
Private Instance Methods
component_html_classes()
click to toggle source
Calls superclass method
UiBibz::Ui::Core::Forms::Buttons::ButtonGroup#component_html_classes
# File lib/ui_bibz/ui/core/forms/choices/choice_group.rb, line 87 def component_html_classes super << ['button-choice', 'btn-group-toggle', options.delete(:class)] end
component_html_data()
click to toggle source
Calls superclass method
UiBibz::Ui::Core::Component#component_html_data
# File lib/ui_bibz/ui/core/forms/choices/choice_group.rb, line 95 def component_html_data super add_html_data 'toggle', value: 'buttons' if @options[:form].nil? end
component_html_options()
click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/choice_group.rb, line 91 def component_html_options {} end