Class: CF::FormField
Instance Attribute Summary collapse
-
#errors ⇒ Object
Contains error message.
-
#field_type ⇒ Object
field_type for “form” object, e.g.
-
#form_field_params ⇒ Object
Parameters for form fields.
-
#id ⇒ Object
ID of form field.
-
#label ⇒ Object
Label for “form” object, e.g.
-
#required ⇒ Object
required boolean either true or false, e.g.
-
#station_id ⇒ Object
station id attribute required for API Calls.
-
#valid_type ⇒ Object
field_type for “form” object, e.g.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ FormField
constructor
Initializes a new “form” object ===Usage of form.new(hash): line = CF::Line.create(“Digitize”, “Survey”) do |l| CF::Station.create(=> l, :type => “work”) do |s| CF::TaskForm.create(=> s, :title => “Enter text from a business card image”, :instruction => “Describe”) do |i| CF::FormField.new(=> i, :label => “First Name”, :field_type => “SA”, :required => “true”) end end end.
-
#to_s ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}) ⇒ FormField
Initializes a new “form” object
Usage of form.new(hash):
line = CF::Line.create("Digitize", "Survey") do |l|
CF::Station.create({:line => l, :type => "work"}) do |s|
CF::TaskForm.create({:station => s, :title => "Enter text from a business card image", :instruction => "Describe"}) do |i|
CF::FormField.new({:form => i, :label => "First Name", :field_type => "SA", :required => "true"})
end
end
end
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 61 62 63 64 65 66 |
# File 'lib/cf/form_field.rb', line 36 def initialize(={}) @form = [:form] @label = [:label] @field_type = [:field_type] @valid_type = [:valid_type] @required = [:required] if !@form.nil? .delete(:form) party_param = { :body => { :api_key => CF.api_key, :form_field => } } resp = HTTParty.post("#{CF.api_url}#{CF.api_version}/lines/#{CF.account_name}/#{@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 = @form.station.form.form_fields = self return self else @form_field_params = end end |
Instance Attribute Details
#errors ⇒ Object
Contains error message
25 26 27 |
# File 'lib/cf/form_field.rb', line 25 def errors @errors end |
#field_type ⇒ Object
field_type for “form” object, e.g. :field_type => “SA”
10 11 12 |
# File 'lib/cf/form_field.rb', line 10 def field_type @field_type end |
#form_field_params ⇒ Object
Parameters for form fields
22 23 24 |
# File 'lib/cf/form_field.rb', line 22 def form_field_params @form_field_params end |
#id ⇒ Object
ID of form field
16 17 18 |
# File 'lib/cf/form_field.rb', line 16 def id @id end |
#label ⇒ Object
Label for “form” object, e.g. :label => “First Name”
7 8 9 |
# File 'lib/cf/form_field.rb', line 7 def label @label end |
#required ⇒ Object
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 |
#station_id ⇒ Object
station id attribute required for API Calls
19 20 21 |
# File 'lib/cf/form_field.rb', line 19 def station_id @station_id end |
#valid_type ⇒ Object
field_type for “form” object, e.g. :field_type => “SA”
10 11 12 |
# File 'lib/cf/form_field.rb', line 10 def valid_type @valid_type end |
Instance Method Details
#to_s ⇒ Object
:nodoc:
68 69 70 |
# File 'lib/cf/form_field.rb', line 68 def to_s # :nodoc: "{:id => => #{self.id}, :label => #{self.label}, :field_type => #{self.field_type}, :required => #{self.required}, :errors => #{self.errors}}" end |