Class: Formbuilder::ResponseFieldWebsite

Inherits:
ResponseField
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
app/models/formbuilder/response_field_website.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

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

Instance Method Details

#normalize_response(value, all_responses) ⇒ Object



42
43
44
45
46
47
48
# File 'app/models/formbuilder/response_field_website.rb', line 42

def normalize_response(value, all_responses)
  return if value.blank?

  unless value[/^http:\/\//] || value[/^https:\/\//]
    all_responses[self.id.to_s] = "http://#{value}"
  end
end

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



23
24
25
# File 'app/models/formbuilder/response_field_website.rb', line 23

def render_entry(value, opts = {})
  "<a href='#{value}' target='_blank' rel='nofollow'>#{value}</a>"
end

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



27
28
29
# File 'app/models/formbuilder/response_field_website.rb', line 27

def render_entry_text(value, opts = {})
  value
end

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



11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/formbuilder/response_field_website.rb', line 11

def render_input(value, opts = {})
  tag(
    :input,
    type: 'text',
    name: "response_fields[#{self.id}]",
    id: "response_fields_#{self.id}",
    class: "rf-size-#{self[:field_options]['size']}",
    value: value,
    placeholder: 'http://'
  )
end

#sortable_value(value) ⇒ Object



50
51
52
# File 'app/models/formbuilder/response_field_website.rb', line 50

def sortable_value(value)
  value[0..20]
end

#validate_response(value) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'app/models/formbuilder/response_field_website.rb', line 31

def validate_response(value)
  require 'uri'

  # add http if not present
  value = "http://#{value}" unless value[/^http:\/\//] || value[/^https:\/\//]

  if !(value =~ URI::regexp) # this doesn't really validate, since almost *anything* matches
    "isn't a valid URL."
  end
end