Class: EnumField
- Inherits:
-
StringField
- Object
- Field
- StringField
- EnumField
- Defined in:
- lib/yodel/models/core/fields/enum_field.rb
Constant Summary
Constants inherited from Field
Instance Attribute Summary
Attributes inherited from Field
Instance Method Summary collapse
-
#default_input_type ⇒ Object
class << self undef search_terms_set end.
Methods inherited from StringField
#from_json, #search_terms_set, #untypecast
Methods inherited from Field
#display?, field_from_type, #from_json, from_options, #include_in_search_keywords?, #index?, #inherited?, #initialize, #method_missing, #numeric?, #required?, #searchable?, #strip_nil?, #to_json, #to_str, #typecast, #unique?, #untypecast, #validate
Constructor Details
This class inherits a constructor from Field
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Field
Instance Method Details
#default_input_type ⇒ Object
class << self
undef search_terms_set
end
def self.to_html_field(record, field, value)
if value.nil? && !field.default.nil?
value = field.default
end
value = value.to_s
= field.values.collect do |enum_value|
= {value: enum_value}
[:selected] = 'selected' if value == enum_value
Hpricot::Elem.new('option', , [Hpricot::Text.new(enum_value)])
end
if field.show_blank || !field.required
= {value: ''}
text = field.blank_text || 'None'
[:selected] = 'selected' if value == ''
.unshift(Hpricot::Elem.new('option', , [Hpricot::Text.new(text)]))
end
Hpricot::Elem.new('select', {name: field.name}, )
end
28 29 30 |
# File 'lib/yodel/models/core/fields/enum_field.rb', line 28 def default_input_type :enum end |