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, #inline_hint, #label, #model, #model_name, #name, #parent, #readonly, #required, #tag, #turbolink, #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, number_format, #simple_value, singular_name
Constructor Details
#initialize(h = {}) ⇒ DateField
Returns a new instance of DateField.
333 334 335 336 337 338 339 340 |
# File 'lib/forma/field.rb', line 333 def initialize(h = {}) h = h.symbolize_keys @formatter = h[:formatter] @@date_counter ||= 0 @@date_counter += 1 @date_counter = @@date_counter super(h) end |
Instance Attribute Details
#formatter ⇒ Object (readonly)
Returns the value of attribute formatter.
331 332 333 |
# File 'lib/forma/field.rb', line 331 def formatter @formatter end |
Instance Method Details
#edit_element(val) ⇒ Object
347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/forma/field.rb', line 347 def edit_element(val) input_id = "ff-date-#{@date_counter}" val = Date.strptime(val) if (val.present? and val.is_a?(String)) rescue nil el('div', children: [ el('input', attrs: { id: input_id, name: parameter_name, value: val.to_s, type: 'hidden' }), el('input', attrs: { class: 'ff-date', type: 'text', value: (val.strftime('%d-%b-%Y') if val.present?), autofocus: @autofocus, style: { width: "#{width || 100}px" }, 'data-altfield' => input_id, }) ]) end |