Class: CF::FormField

Inherits:
Object
  • Object
show all
Includes:
Client
Defined in:
lib/cf/form_field.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (FormField) initialize(options = {})

Initializes a new "form_field" object

Usage of form_field.new(hash):

line = CF::Line.create("Digitize", "Survey") do |l|   
  CF::Station.create({:line => l, :type => "work"}) do |s|
    CF::StandardInstruction.create({:station => s, :title => "Enter text from a business card image", :description => "Describe"}) do |i|
      CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
    end
  end
end


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/cf/form_field.rb', line 31

def initialize(options={})
  @form  = options[:form]
  @label        = options[:label]
  @field_type   = options[:field_type]
  @required     = options[:required]
  
  if !@form.nil?
    options.delete(:form)
    party_param = 
    {
      :body => 
      {
        :api_key => CF.api_key,
        :form_field => options
      }
    }
    resp =  HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.}/#{@form.station.line['title'].downcase}/stations/#{@form.station.index}/form_fields.json",party_param)
    resp.parsed_response.each_pair do |k,v|
      self.send("#{k}=",v) if self.respond_to?(k)
    end
    if resp.code != 200
      self.errors = resp.parsed_response['error']['message']
    end
    self.form_field_params = options
    @form.station.form.form_fields = self
    return self
  else
    @form_field_params = options
  end
end

Instance Attribute Details

- (Object) errors

Returns the value of attribute errors



20
21
22
# File 'lib/cf/form_field.rb', line 20

def errors
  @errors
end

- (Object) field_type

field_type for "form_field" object, e.g. :field_type => "SA"



10
11
12
# File 'lib/cf/form_field.rb', line 10

def field_type
  @field_type
end

- (Object) form_field_params

Returns the value of attribute form_field_params



20
21
22
# File 'lib/cf/form_field.rb', line 20

def form_field_params
  @form_field_params
end

- (Object) id

ID of form field



16
17
18
# File 'lib/cf/form_field.rb', line 16

def id
  @id
end

- (Object) label

Label for "form_field" object, e.g. :label => "First Name"



7
8
9
# File 'lib/cf/form_field.rb', line 7

def label
  @label
end

- (Object) required

required boolean either true or false, e.g. :required => "true" & if false then you don't need to mention



13
14
15
# File 'lib/cf/form_field.rb', line 13

def required
  @required
end

- (Object) station_id

station id attribute required for API Calls



19
20
21
# File 'lib/cf/form_field.rb', line 19

def station_id
  @station_id
end