Class: Dima::Html::BooleanField

Inherits:
SimpleField show all
Defined in:
lib/dima/html/field.rb

Overview

Boolean field.

Instance Attribute Summary

Attributes inherited from SimpleField

#height, #klass, #lambda, #model, #name, #readonly, #width

Attributes inherited from Field

#after, #align, #before, #edit, #form, #has_errors, #hint, #label, #required, #tooltip, #url

Instance Method Summary collapse

Methods inherited from SimpleField

#<<, #>>, #empty?, #main_content_node, #readonly?

Methods inherited from Field

#after_node, #before_node, #edit?, #empty_node, #label_node, #options, #to_n, #url_node, #val, #val=, #validate, #value_node

Methods included from Init

#initialize

Methods inherited from Element

#id, #id=

Instance Method Details

#simple_value_nodeObject



352
353
354
355
356
357
358
# File 'lib/dima/html/field.rb', line 352

def simple_value_node
  if self.edit?
    Node.new(tag: 'input', attributes: { name: "dim[#{name}]", class: 'dim-main-content dim-boolean', type: 'checkbox', checked: self.val })
  else
    Node.new(tag: 'input', attributes: { class: 'dim-main-content dim-boolean', type: 'checkbox', checked: self.val, disabled: true })
  end
end

#value_from_text(val) ⇒ Object



360
361
362
363
364
365
366
# File 'lib/dima/html/field.rb', line 360

def value_from_text(val)
  if Dima::Utils.empty?(val) || val.strip.downcase == 'false'
    self.val = false
  else
    self.val = true
  end
end