class UiBibz::Ui::Core::Forms::Choices::BoxSwitchField

Create a SurroundField

This element is an extend of UiBibz::Ui::Core::Component. Source : www.bootstrap-switch.org/documentation-2.html

Attributes

Options

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

Signatures

UiBibz::Ui::Core::Forms::BoxSwitchField.new(content, options = {}, html_options = {}).render

UiBibz::Ui::Core::Forms::BoxSwitchField.new(options = {}, html_options = {}) do
  content
end.render

Examples

box_switch_field 'name', { on_color: :primary }, { readonly: true }

Helper

box_switch_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/box_switch_field.rb, line 52
def pre_render
  box_switch_field_html_tag
end

Private Instance Methods

animate() click to toggle source

true, false => default : true

# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 99
def animate
  add_html_data('animate', value: options.delete(:animate)) unless options[:animate].nil?
end
box_switch_field_html_tag() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 58
def box_switch_field_html_tag
  content_tag :div, class: component_wrapper_html_classes do
    concat hidden_field_tag content, '0'
    concat check_box_tag content, '1', html_options[:checked], html_options
  end
end
component_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 73
def component_html_classes
  super << 'switch-field'
end
component_html_data() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 77
def component_html_data
  super
  size
  state
  animate
  left_color
  right_color
  left_text
  right_text
  middle_text
end
component_wrapper_html_classes() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 69
def component_wrapper_html_classes
  join_classes('switch-field-container', inline)
end
inline() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 133
def inline
  'btn-group' unless options[:inline].nil?
end
left_color() click to toggle source

'primary', 'info', 'success', 'warning', 'danger', 'default' => default : default

# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 109
def left_color
  add_html_data('on_color', value: options[:left_color]) unless options[:left_color].nil?
end
left_text() click to toggle source

String => default : “ON”

# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 119
def left_text
  add_html_data('on_text', value: options[:left_text]) unless options[:left_text].nil?
end
matching_size() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 94
def matching_size
  { sm: 'small', md: 'normal', lg: 'large' }
end
middle_text() click to toggle source

String => default : '&nbsp;'

# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 129
def middle_text
  add_html_data('label_text', value: options[:middle_text]) unless options[:middle_text].nil?
end
right_color() click to toggle source

'primary', 'info', 'success', 'warning', 'danger', 'default' => default : default

# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 114
def right_color
  add_html_data('off_color', value: options[:right_color]) unless options[:right_color].nil?
end
right_text() click to toggle source

String => default : “OFF”

# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 124
def right_text
  add_html_data('off_text', value: options[:right_text]) unless options[:right_text].nil?
end
size() click to toggle source

'', 'mini', 'small', 'normal', 'large'

# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 90
def size
  add_html_data('size', value: matching_size[options[:size]]) unless options[:size].nil?
end
state() click to toggle source

active, disabled => default : active

# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 104
def state
  html_options[:disabled] = true if options[:state] == 'disabled'
end
value() click to toggle source
# File lib/ui_bibz/ui/core/forms/choices/box_switch_field.rb, line 65
def value
  options[:value]
end