Class: Forma::DateField
- Inherits:
-
SimpleField
- Object
- Field
- SimpleField
- Forma::DateField
- Defined in:
- lib/forma/field.rb
Overview
Date feild.
Instance Attribute Summary collapse
-
#formatter ⇒ Object
readonly
Returns the value of attribute formatter.
Attributes inherited from Field
#actions, #after, #autofocus, #before, #child_model_name, #height, #hint, #i18n, #icon, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #url, #value, #width
Instance Method Summary collapse
- #edit_element(val) ⇒ Object
-
#initialize(h = {}) ⇒ DateField
constructor
A new instance of DateField.
- #view_element(val) ⇒ Object
Methods inherited from SimpleField
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, #simple_value, singular_name
Constructor Details
#initialize(h = {}) ⇒ DateField
Returns a new instance of DateField.
336 337 338 339 340 |
# File 'lib/forma/field.rb', line 336 def initialize(h = {}) h = h.symbolize_keys @formatter = h[:formatter] super(h) end |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
334 335 336 |
# File 'lib/forma/field.rb', line 334 def formatter @formatter end |
Instance Method Details
#edit_element(val) ⇒ Object
346 347 348 349 350 351 352 353 354 |
# File 'lib/forma/field.rb', line 346 def edit_element(val) el('input', attrs: { name: parameter_name, type: 'text', value: val.to_s, autofocus: @autofocus, style: { width: ("#{width}px" if width.present?) } }) end |
#view_element(val) ⇒ Object
342 343 344 |
# File 'lib/forma/field.rb', line 342 def view_element(val) el('span', text: val.localtime.strftime(formatter || Forma.config.date.formatter)) end |