tyform

package
v0.0.0-...-b237f9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2016 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

The fields package contains all the fields to represent forms and their associated metadata. Each of these matches a field in the [Fields](http://docs.typeform.io/docs/introduction) section of their api documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Field

type Field struct {
	Type        FieldType `json:"type"                  bson:"t"`
	Question    string    `json:"question"              bson:"q"              validate:"nonzero,max=512"`
	Ref         string    `json:"ref,omitempty"         bson:"r,omitempty"    validate:"max=128"`
	Description string    `json:"description,omitempty" bson:"d"              validate:"max=512"`
	Required    bool      `json:"required,omitempty"    bson:"req,omitempty"`
	Tags        []string  `json:"tags,omitempty"        bson:"g,omitempty"    validate:"arrMap=min=1,arrMap=max=128,max=100"`

	// Value is only included so you can pair up a user's answer with the original field
	Value interface{} `json:"value,omitempty"           bson:"-"`
}

Field is a generic Field that holds common properties of all Fields in a Form

func (*Field) GetDescription

func (f *Field) GetDescription() string

func (*Field) GetQuestion

func (f *Field) GetQuestion() string

func (*Field) GetRef

func (f *Field) GetRef() string

func (*Field) GetRequired

func (f *Field) GetRequired() bool

func (*Field) GetTags

func (f *Field) GetTags() []string

func (*Field) GetType

func (f *Field) GetType() FieldType

Various methods for getting common fields off of a Field

func (*Field) GetValue

func (f *Field) GetValue() interface{}

func (*Field) SetValue

func (f *Field) SetValue(v interface{})

type FieldInterface

type FieldInterface interface {
	GetType() FieldType
	GetQuestion() string
	GetRef() string
	GetDescription() string
	GetRequired() bool
	GetTags() []string
	GetValue() interface{}
	SetValue(v interface{})
}

FieldInterface can be used to get common properties off of the various types of Field's on a Form

type FieldType

type FieldType string

FieldType describes the type of field

var (
	TypeStatement      FieldType = "statement"
	TypeOpinionScale   FieldType = "opinion_scale"
	TypeMultipleChoice FieldType = "multiple_choice"
	TypeYesNo          FieldType = "yes_no"
)

type Form

type Form struct {
	FormMetadata `bson:",inline"`
	Fields       []FieldInterface `json:"fields"             bson:"f"           validate:"min=1,max=500"`
}

A Form is a group of Fields that can be submitted to TypeForm's [/forms](http://docs.typeform.io/docs/forms) endpoint

func (*Form) SetBSON

func (f *Form) SetBSON(raw bson.Raw) error

SetBSON implements the bson.Setter interface

func (*Form) UnmarshalJSON

func (f *Form) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type FormMetadata

type FormMetadata struct {
	Title      string   `json:"title"                        bson:"t"           validate:"min=1,max=256"`
	Tags       []string `json:"tags,omitempty"               bson:"g,omitempty" validate:"arrMap=min=1,arrMap=max=128,max=100"`
	WebhookURL string   `json:"webhook_submit_url,omitempty" bson:"w,omitempty" validate:"validateURL"`
	DesignID   string   `json:"design_id,omitempty"          bson:"d,omitempty" validate:"max=128"`
}

FormMetadata represents everything about a Form except for the Fields

type MultipleChoice

type MultipleChoice struct {
	Field   `bson:",inline"`
	Choices []MultipleChoiceChoice `json:"choices"      bson:"c"              validate:"min=1,max=25"`
}

MultipleChoice is a question that contains multiple choices

type MultipleChoiceChoice

type MultipleChoiceChoice struct {
	Label string `json:"label"                          bson:"l"              validate:"nonzero, max=512"`
}

MultipleChoiceChoice is a choice in a MultipleChoice's Choices slice

type OpinionLabels

type OpinionLabels struct {
	Left   string `json:"left,omitempty"                bson:"l,omitempty"    validate:"max=100"`
	Center string `json:"center,omitempty"              bson:"c,omitempty"    validate:"max=100"`
	Right  string `json:"right,omitempty"               bson:"r,omitempty"    validate:"max=100"`
}

OpinionLabels represents a OpinionScale's labels property It contains a label for the left, center, and right sides of the scale

type OpinionScale

type OpinionScale struct {
	Field      `bson:",inline"`
	Steps      int64         `json:"steps"                  bson:"s"              validate:"min=5,max=11"`
	StartAtOne bool          `json:"start_at_one,omitempty" bson:"sao,omitempty"`
	Labels     OpinionLabels `json:"labels,omitempty"       bson:"l,omitempty"`
}

OpinionScale is a scale from 0-(steps - 1)

type Statement

type Statement struct {
	Field      `bson:",inline"`
	ButtonText string `json:"button_text,omitempty"     bson:"b,omitempty"    validate:"max=128"`
	HideMarks  bool   `json:"hide_marks,omitempty"      bson:"h,omitempty"`
}

Statement is just text, no question to answer

type YesNo

type YesNo struct {
	Field `bson:",inline"`
}

YesNo is just text, with yes/no selector

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL