Class: Formidable::Elements::Select

Inherits:
ElementList show all
Includes:
Validations
Defined in:
lib/formidable/elements.rb

Constant Summary

Constants included from Rendering

Rendering::RendererNotAssigned

Instance Attribute Summary

Attributes inherited from BasicElement

#attributes, #content, #name, #tag

Attributes included from Rendering

#renderer

Instance Method Summary collapse

Methods included from Validations

#errors, register_validation, #valid?, #validate, #validations

Methods inherited from ElementList

#content, #elements, register, #set_prefix

Methods included from GroupValidations

#before_validate, #errors, register_validation, #valid?, #validate, #validations

Methods included from Rendering

included, #render

Constructor Details

#initialize(name, attributes = Hash.new, &block) ⇒ Select

Returns a new instance of Select.



274
275
276
# File 'lib/formidable/elements.rb', line 274

def initialize(name, attributes = Hash.new, &block)
  super(:select, name, attributes, &block)
end

Instance Method Details

#cleaned_dataObject



300
301
302
# File 'lib/formidable/elements.rb', line 300

def cleaned_data
  self.selected && self.selected.cleaned_data
end

#raw_dataObject



284
285
286
# File 'lib/formidable/elements.rb', line 284

def raw_data
  self.selected.raw_data if self.selected
end

#raw_data=(raw_data) ⇒ Object



288
289
290
291
292
293
294
295
296
297
298
# File 'lib/formidable/elements.rb', line 288

def raw_data=(raw_data)
  if raw_data.nil?
    self.selected.attributes.delete(:selected)
  else
    self.elements.find do |element|
      if element.raw_data == raw_data
        element.attributes[:selected] = true
      end
    end
  end
end

#selectedObject



278
279
280
281
282
# File 'lib/formidable/elements.rb', line 278

def selected
  self.elements.find do |element|
    element.attributes[:selected]
  end
end