class CustomAttributes::BoolFieldType

Public Instance Methods

cast_single_value(_custom_field, value, _customizable = nil) click to toggle source
# File lib/custom_attributes/field_types/bool_field_type.rb, line 11
def cast_single_value(_custom_field, value, _customizable = nil)
  value == '1'
end
edit_tag(view, tag_id, tag_name, custom_value, options = {}) click to toggle source

Boolean supports either checkbox, radiobutton or select field as edit tag

# File lib/custom_attributes/field_types/bool_field_type.rb, line 29
def edit_tag(view, tag_id, tag_name, custom_value, options = {})
  case custom_value.custom_field.edit_tag_style
  when 'check_box'
    single_check_box_edit_tag(view, tag_id, tag_name, custom_value, options)
  when 'radio'
    check_box_edit_tag(view, tag_id, tag_name, custom_value, options)
  else
    select_edit_tag(view, tag_id, tag_name, custom_value, options)
  end
end
label() click to toggle source
# File lib/custom_attributes/field_types/bool_field_type.rb, line 7
def label
  'label_boolean'
end
possible_values_options(_custom_field, _object = nil) click to toggle source

Boolean supports either True or False as value

# File lib/custom_attributes/field_types/bool_field_type.rb, line 16
def possible_values_options(_custom_field, _object = nil)
  [[::I18n.t(:general_text_Yes), '1'], [::I18n.t(:general_text_No), '0']]
end
single_check_box_edit_tag(view, tag_id, tag_name, custom_value, options = {}) click to toggle source

Renders the edit tag as a simple check box

# File lib/custom_attributes/field_types/bool_field_type.rb, line 41
def single_check_box_edit_tag(view, tag_id, tag_name, custom_value, options = {})
  s = ''.html_safe
  s << view.hidden_field_tag(tag_name, '0', id: nil)
  s << view.check_box_tag(tag_name, '1', custom_value.value.to_s == '1', id: tag_id)
  view.content_tag('span', s, options)
end
validate_single_value(_custom_field, value, _customizable = nil) click to toggle source
# File lib/custom_attributes/field_types/bool_field_type.rb, line 20
def validate_single_value(_custom_field, value, _customizable = nil)
  if value == '0' || value == '1'
    []
  else
    [::I18n.t('activerecord.errors.messages.not_a_boolean')]
  end
end