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, #search_type, #serialized, #sort_as_numeric

Instance Method Summary collapse

Methods inherited from ResponseField

#before_response_destroyed, #has_length_validations?, #length_validations, #max, #maxlength, #min, #min_max_length_units, #min_max_validations, #minlength, #normalize_response, #options_array, #transform_raw_value, #validate_response

Instance Method Details

#audit_response(value, all_responses) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/models/formbuilder/response_field_address.rb', line 63

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



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

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

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



57
58
59
60
61
# File 'app/models/formbuilder/response_field_address.rb', line 57

def render_entry_text(value, opts = {})
  "#{value['street']}\n" +
  "#{value['city']} #{value['state']} #{value['zipcode']}\n" +
  "#{value['country']}"
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/models/formbuilder/response_field_address.rb', line 10

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]' id='response_fields_#{self[:id]}' 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

#sortable_value(value) ⇒ Object



76
77
78
# File 'app/models/formbuilder/response_field_address.rb', line 76

def sortable_value(value)
  "#{value['street']} #{value['city']} #{value['state']} #{value['zipcode']} #{value['country']}"
end