class UiBibz::Ui::Core::Forms::Choices::ChoiceGroup

Create a choice group

This element is an extend of UiBibz::Ui::Core::Forms::Choices::ButtonGroup

Attributes

Options

You can add HTML attributes using the html_options. You can pass arguments in options attribute:

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

# 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
# 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
# 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