class UiBibz::Ui::Core::Forms::Choices::CheckboxField

Create a checkbox

This element is an extend of UiBibz::Ui::Core::Component.

Attributes

Options

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

Signatures

UiBibz::Ui::Core::Forms::CheckboxField.new(content, options = nil, html_options = nil)

UiBibz::Ui::Core::Forms::CheckboxField.new(options = nil, html_options = nil) do
  content
end

Examples

UiBibz::Ui::Core::Forms::CheckboxField.new(content, { status: :success, type: :circle },{ class: 'test' }).render

UiBibz::Ui::Core::Forms::CheckboxField.new({ status: :primary }, { class: 'test' }) do
  content
end.render

Helper

ui_checkbox_field(content, options = {}, html_options = {})

ui_checkbox_field(options = {}, html_options = {}) do
  content
end

Public Instance Methods

pre_render() click to toggle source

Render html tag

# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 56
def pre_render
  content_tag :div, wrapper_html_options  do
    concat hidden_field_tag(content, '0', id: "#{content}-hidden") if options[:boolean]
    concat check_box_tag(content, options[:value] || '1', options[:checked] || html_options[:checked], checkbox_html_options)
    concat label_tag(label_name, label_content, label_html_options) if options[:label] != false
  end
end

Private Instance Methods

checkbox_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 78
def checkbox_html_options
  html_options.merge({
                       disabled: disabled?,
                       checked: html_options[:checked] || options[:state] == :active,
                       indeterminate: options[:indeterminate]
                     })
end
component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 101
def component_html_classes
  super << ['form-check-input', input_status]
end
inline() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 111
def inline
  'form-check-inline' if options[:inline]
end
input_status() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 105
def input_status
  "form-check-input-#{options[:status]}" if options[:status]
end
label_classes() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 119
def label_classes
  'form-check-label'
end
label_content() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 90
def label_content
  case options[:label]
  when nil
    content
  when false
    ' '
  else
    options[:label]
  end
end
label_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 72
def label_html_options
  (options[:label_html] || {}).tap do |option|
    option[:class] = UiBibz::Utils::Screwdriver.join_classes(label_classes, options[:label_html].try(:[], :class))
  end
end
label_name() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 86
def label_name
  html_options[:id] || content
end
status() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 109
def status; end
wrapper_classes() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 115
def wrapper_classes
  'form-check'
end
wrapper_html_options() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/checkbox_field.rb, line 66
def wrapper_html_options
  (options[:wrapper_html] || {}).tap do |option|
    option[:class] = UiBibz::Utils::Screwdriver.join_classes(wrapper_classes, inline, options[:wrapper_html].try(:[], :class))
  end
end