Class: Dima::Html::SelectField
- Inherits:
-
SimpleField
- Object
- Element
- Field
- SimpleField
- Dima::Html::SelectField
- Defined in:
- lib/dima/html/field.rb
Instance Attribute Summary collapse
-
#collection ⇒ Object
Returns the value of attribute collection.
-
#empty ⇒ Object
Returns the value of attribute empty.
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
Methods inherited from Element
Instance Attribute Details
#collection ⇒ Object
Returns the value of attribute collection.
371 372 373 |
# File 'lib/dima/html/field.rb', line 371 def collection @collection end |
#empty ⇒ Object
Returns the value of attribute empty.
372 373 374 |
# File 'lib/dima/html/field.rb', line 372 def empty @empty end |
Instance Method Details
#simple_value_node ⇒ Object
374 375 376 377 378 379 380 381 382 383 384 385 386 |
# File 'lib/dima/html/field.rb', line 374 def simple_value_node if self.edit? id = self.val.id rescue nil node = Node.new(tag: 'select', attributes: { name: "dim[#{name}]", class: 'dim-main-content dim-select' }) node << Node.new(tag: 'option', attributes: { selected: (id == nil), value: '' }, text: self.empty) if self.empty self.collection.each do |v| node << Node.new(tag: 'option', attributes: { value: v.id, selected: (v.id == id) }, text: v.to_s) end if self.collection node else Node.new(tag: 'span', attributes: { class: 'dim-select' }, text: self.val.to_s) end end |
#value_from_text(val) ⇒ Object
388 389 390 391 392 393 394 395 |
# File 'lib/dima/html/field.rb', line 388 def value_from_text(val) self.collection.each do |v| if val == v.id.to_s self.val = v #.id break end end if self.collection end |