Class: Formbuilder::ResponseFieldDate

Inherits:
ResponseField
  • Object
show all
Defined in:
app/models/formbuilder/response_field_date.rb

Constant Summary

Constants inherited from ResponseField

Formbuilder::ResponseField::ALLOWED_PARAMS

Instance Attribute Summary

Attributes inherited from ResponseField

#cid, #field_type, #input_field, #options_field, #serialized, #sort_as_numeric

Instance Method Summary collapse

Methods inherited from ResponseField

#audit_response, #has_length_validations?, #length_validations, #min_max_validations, #render_entry_for_table

Instance Method Details

#render_entry(value, opts = {}) ⇒ Object



35
36
37
# File 'app/models/formbuilder/response_field_date.rb', line 35

def render_entry(value, opts = {})
  "#{value['month']}/#{value['day']}/#{value['year']}"
end

#render_input(value, opts = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/models/formbuilder/response_field_date.rb', line 10

def render_input(value, opts = {})
  """
    <div class='input-line'>
      <span class='month'>
        <input type='text' name='response_fields[#{self[:id]}][month]' value='#{value['month']}' maxlength='2' />
        <label>MM</label>
      </span>

      <span class='above-line'>/</span>

      <span class='day'>
        <input type='text' name='response_fields[#{self[:id]}][day]' value='#{value['day']}' maxlength='2' />
        <label>DD</label>
      </span>

      <span class='above-line'>/</span>

      <span class='year'>
        <input type='text' name='response_fields[#{self[:id]}][year]' value='#{value['year']}' maxlength='4' />
        <label>YYYY</label>
      </span>
    </div>
  """
end

#validate_response(value) ⇒ Object



39
40
41
42
43
# File 'app/models/formbuilder/response_field_date.rb', line 39

def validate_response(value)
  if value['year'].to_i == 0 || !(DateTime.new(value['year'].to_i, value['month'].to_i, value['day'].to_i) rescue false)
    "isn't a valid date."
  end
end