Class: Formbuilder::ResponseFieldNumber

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



22
23
24
# File 'app/models/formbuilder/response_field_number.rb', line 22

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

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



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

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

  if (units = self[:field_options]['units'].presence)
    str += "<span class='units'>#{units}</span>".html_safe
  end

  str
end

#validate_response(value) ⇒ Object



26
27
28
29
30
# File 'app/models/formbuilder/response_field_number.rb', line 26

def validate_response(value)
  unless (Float(value) rescue nil)
    "isn't a valid number."
  end
end