Class: Forma::SimpleField

Inherits:
Field
  • Object
show all
Defined in:
lib/forma/field.rb

Overview

SimpleField gets it’s value from it’s name.

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

Methods inherited from Field

#action, #id, #localization_key, #localized_hint, #localized_label, #name_as_chain, #parameter_name, #to_html

Methods included from Html

attr, el

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

#errorsObject



255
256
257
# File 'lib/forma/field.rb', line 255

def errors
  if self.model.respond_to?(:errors); self.model.errors.messages[name.to_sym] end || []
end

#has_errors?Boolean

Returns:

  • (Boolean)


259
260
261
# File 'lib/forma/field.rb', line 259

def has_errors?
  errors.any?
end

#valueObject



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