Class: Forma::SimpleField
Overview
SimpleField gets it’s value from it’s name.
Direct Known Subclasses
ArrayField, BooleanField, ComboField, DateField, FileField, ImageField, SelectField, SubformField, TableField, TextField
Instance Attribute Summary
Attributes inherited from Field
#actions, #after, #autofocus, #before, #child_model_name, #height, #hint, #i18n, #icon, #inline_hint, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #turbolink, #url, #width
Instance Method Summary collapse
- #errors ⇒ Object
- #has_errors? ⇒ Boolean
-
#initialize(h = {}) ⇒ SimpleField
constructor
A new instance of SimpleField.
- #value ⇒ Object
Methods inherited from Field
#action, #id, #localization_key, #localized_hint, #localized_label, #name_as_chain, #parameter_name, #to_html
Methods included from Html
Methods included from Utils
extract_value, number_format, #simple_value, singular_name
Constructor Details
#initialize(h = {}) ⇒ SimpleField
Returns a new instance of SimpleField.
243 244 245 246 |
# File 'lib/forma/field.rb', line 243 def initialize(h = {}) h = h.symbolize_keys super(h) end |
Instance Method Details
#errors ⇒ Object
255 256 257 |
# File 'lib/forma/field.rb', line 255 def errors if self.model.respond_to?(:errors); self.model.errors.[name.to_sym] end || [] end |
#has_errors? ⇒ Boolean
259 260 261 |
# File 'lib/forma/field.rb', line 259 def has_errors? errors.any? end |
#value ⇒ Object
248 249 250 251 252 253 |
# File 'lib/forma/field.rb', line 248 def value val = super if val then val else extract_value(self.model, self.name) end end |