Module: Releaf::Builders::FormBuilder::DateFields

Included in:
Fields
Defined in:
app/builders/releaf/builders/form_builder/date_fields.rb

Instance Method Summary collapse

Instance Method Details

#date_or_time_field(name, type, input: {}, label: {}, field: {}, options: {}) ⇒ Object



2
3
4
5
6
# File 'app/builders/releaf/builders/form_builder/date_fields.rb', line 2

def date_or_time_field(name, type, input: {}, label: {}, field: {}, options: {})
  input = date_or_time_field_input_attributes(name, type, input)
  options = {field: {type: type.to_s}}.deep_merge(options)
  releaf_text_field(name, input: input, label: label, field: field, options: options)
end

#date_or_time_field_input_attributes(name, type, attributes) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'app/builders/releaf/builders/form_builder/date_fields.rb', line 8

def date_or_time_field_input_attributes(name, type, attributes)
  {
    class: "text #{type}-picker",
    value: Releaf::Builders::Utilities::DateFields.format_date_or_time_value(object.send(name), type),
    data: {
      "date-format" => Releaf::Builders::Utilities::DateFields.date_format_for_jquery,
      "time-format" => Releaf::Builders::Utilities::DateFields.time_format_for_jquery
    }
  }.deep_merge(attributes)
end

#releaf_date_field(name, input: {}, label: {}, field: {}, options: {}) ⇒ Object



27
28
29
# File 'app/builders/releaf/builders/form_builder/date_fields.rb', line 27

def releaf_date_field(name, input: {}, label: {}, field: {}, options: {})
  date_or_time_field(name, :date, input: input, label: label, field: field, options: options)
end

#releaf_datetime_field(name, input: {}, label: {}, field: {}, options: {}) ⇒ Object



19
20
21
# File 'app/builders/releaf/builders/form_builder/date_fields.rb', line 19

def releaf_datetime_field(name, input: {}, label: {}, field: {}, options: {})
  date_or_time_field(name, :datetime, input: input, label: label, field: field, options: options)
end

#releaf_time_field(name, input: {}, label: {}, field: {}, options: {}) ⇒ Object



23
24
25
# File 'app/builders/releaf/builders/form_builder/date_fields.rb', line 23

def releaf_time_field(name, input: {}, label: {}, field: {}, options: {})
  date_or_time_field(name, :time, input: input, label: label, field: field, options: options)
end