Class: Formbuilder::ResponseFieldAddress

Inherits:
ResponseField
  • Object
show all
Defined in:
app/models/formbuilder/response_field_address.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

#has_length_validations?, #length_validations, #min_max_validations, #render_entry_for_table, #validate_response

Instance Method Details

#audit_response(value, all_responses) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'app/models/formbuilder/response_field_address.rb', line 56

def audit_response(value, all_responses)
  begin
    coords = Geocoder.coordinates("#{value['street']} #{value['city']} " +
                                  "#{value['state']} #{value['zipcode']} #{value['country']}")

    all_responses["#{self.id}_x"] = coords[0]
    all_responses["#{self.id}_y"] = coords[1]
  rescue
    all_responses["#{self.id}_x"] = nil
    all_responses["#{self.id}_y"] = nil
  end
end

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



48
49
50
51
52
53
54
# File 'app/models/formbuilder/response_field_address.rb', line 48

def render_entry(value, opts = {})
  """
    #{value['street']}<br />
    #{value['city']} #{value['state']} #{value['zipcode']}<br />
    #{value['country']}
  """
end

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/models/formbuilder/response_field_address.rb', line 9

def render_input(value, opts = {})
  selected_country = (value['country'] || 'US').to_sym

  """
    <div class='input-line'>
      <span class='street'>
        <input type'text' name='response_fields[#{self[:id]}][street]' value='#{value['street']}' />
        <label>Address</label>
      </span>
    </div>

    <div class='input-line'>
      <span class='city'>
        <input type'text' name='response_fields[#{self[:id]}][city]' value='#{value['city']}' />
        <label>City</label>
      </span>

      <span class='state'>
        <input type'text' name='response_fields[#{self[:id]}][state]' value='#{value['state']}' />
        <label>State / Province / Region</label>
      </span>
    </div>

    <div class='input-line'>
      <span class='zip'>
        <input type'text' name='response_fields[#{self[:id]}][zipcode]' value='#{value['zipcode']}' />
        <label>Zipcode</label>
      </span>

      <span class='country'>
        <select name='response_fields[#{self[:id]}][country]'>
          #{country_options(selected_country)}
        </select>
        <label>Country</label>
      </span>
    </div>
  """
end