Documentation
¶
Index ¶
- Constants
- Variables
- func IsAssetType(qt QuestionType) bool
- func IsChoiceType(qt QuestionType) bool
- func IsComplexChoiceType(qt QuestionType) bool
- func IsExternalType(qt QuestionType) bool
- func IsSimpleChoiceType(qt QuestionType) bool
- func IsTextType(qt QuestionType) bool
- type QBase
- type QuestionType
Constants ¶
const ( // QTypeSingleSelect represents a single select field type QTypeSingleSelect QuestionType = "single_select" // QTypeMultipleSelect represents a multiple select field type QTypeMultipleSelect = "multi_select" // QTypeRadio represents a radio field type QTypeRadio = "radio" // QTypeCheckbox represents a checkbox field type QTypeCheckbox = "checkbox" // QTypeToggle represents a toggle field type QTypeToggle = "toggle" // QTypeSlider represents a slider field type QTypeSlider = "slider" // QTypeTextArea represents a text area field type QTypeTextArea = "text_area" // QTypeInputText represents a text input field type QTypeInputText = "input_text" // QTypeEmail represents an email input field type QTypeEmail = "email" // QTypeTelephone represents a telephone input field type QTypeTelephone = "telephone" // QTypeInformation represents an information field type QTypeInformation = "information" // QTypeIdentificationNumber represents an identification number field type QTypeIdentificationNumber = "identification_number" // QTypeDateTime represents a date time field type QTypeDateTime = "date_time" // QTypeImage represents an image field type QTypeImage = "image" // QTypeVideo represents a video field type QTypeVideo = "video" // QTypeAudio represents an audio field type QTypeAudio = "audio" // QTypeDocument represents a document field type QTypeDocument = "document" // QTypeExternalQuestion represents a external question field type QTypeExternalQuestion = "external_question" )
Any new type, depending on the type of question, should be added to the following maps: - Maps:
- QTypeChoiceTypes if type is a choice type
- QTypeTextTypes if type is a text type
- QTypeAssetTypes if type is an asset type
- Add to serde functions:
- question.UnmarshalJSON
- question.UnmarshalBSONValue
- Add reviewer function to reviewer.GetQuestionReviewer
if the new type cant be added to either of the above, then: - add new types below - create a new map of QuestionType and add the new types to it (e.g. QTypeChoiceTypes or QTypeTextTypes) - create new struct for the new type (e.g. choice.Choice) - add new map to ParseToQuestionType function - add a new function to check if the new type is of the new slice (e.g. IsChoiceType or IsTextType) - add reviewer function for the new type in reviewer.GetQuestionReviewer function - add news struct to the switch case in question.UnmarshalJSON and question.UnmarshalBSONValue functions - update this comment to include the new type :)
Variables ¶
var QTypeAssetTypes = map[QuestionType]bool{ QTypeImage: true, QTypeVideo: true, QTypeAudio: true, QTypeDocument: true, }
QTypeAssetTypes groups all asset types.
var QTypeChoiceTypes = joinMaps(QTypeSimpleChoiceTypes, QTypeComplexChoiceTypes)
QTypeChoiceTypes groups all choice types.
var QTypeComplexChoiceTypes = map[QuestionType]bool{ QTypeToggle: true, QTypeSlider: true, }
var QTypeExternalQuestions = map[QuestionType]bool{ QTypeExternalQuestion: true, }
QTypeExternalQuestions groups all external types.
var QTypeSimpleChoiceTypes = map[QuestionType]bool{ QTypeSingleSelect: true, QTypeMultipleSelect: true, QTypeRadio: true, QTypeCheckbox: true, }
var QTypeTextTypes = map[QuestionType]bool{ QTypeTextArea: true, QTypeInputText: true, QTypeEmail: true, QTypeTelephone: true, QTypeInformation: true, QTypeIdentificationNumber: true, QTypeDateTime: true, }
QTypeTextTypes groups all text types.
Functions ¶
func IsAssetType ¶ added in v2.1.0
func IsAssetType(qt QuestionType) bool
IsAssetType returns true if the question type is an asset type, false otherwise.
func IsChoiceType ¶
func IsChoiceType(qt QuestionType) bool
IsChoiceType returns true if the question type is a choice type, false otherwise.
func IsComplexChoiceType ¶ added in v2.1.0
func IsComplexChoiceType(qt QuestionType) bool
IsComplexChoiceType returns true if the question type is a complex choice type, false otherwise.
func IsExternalType ¶
func IsExternalType(qt QuestionType) bool
IsExternalType returns true if the question type is an external type, false otherwise.
func IsSimpleChoiceType ¶ added in v2.1.0
func IsSimpleChoiceType(qt QuestionType) bool
IsSimpleChoiceType returns true if the question type is a simple choice type, false otherwise.
func IsTextType ¶
func IsTextType(qt QuestionType) bool
IsTextType returns true if the question type is a text type, false otherwise.
Types ¶
type QBase ¶
type QBase struct {
// Placeholder is a placeholder text.
// Validations:
// - optional
// - min length: 1
Placeholder *string `json:"placeholder,omitempty" bson:"placeholder,omitempty" validate:"omitempty,min=1"`
// Metadata is a map of key-value pairs that can be used to store additional information about the question.
// Validations:
// - optional
Metadata map[string]any `json:"metadata,omitempty" bson:"metadata,omitempty" validate:"omitempty"`
// Collapsible is a flag that indicates if the question is collapsible.
// Validations:
// - optional
Collapsible *bool `json:"collapsible,omitempty" bson:"collapsible,omitempty"`
// Collapsed is a flag that indicates if the question is collapsed.
// Validations:
// - optional
Collapsed *bool `json:"collapsed,omitempty" bson:"collapsed,omitempty"`
// Color is the color of the question.
// Validations:
// - optional
// - min length: 1
Color *string `json:"color,omitempty" bson:"color,omitempty" validate:"omitempty,min=1"`
// Defaults is the list of default values for the question.
// Validations:
// - optional
Defaults []string `json:"defaults,omitempty" bson:"defaults,omitempty" validate:"omitempty"`
}
QBase is a struct that contains common fields for all types of questions.
type QuestionType ¶
type QuestionType string
QuestionType represents the different types of questions that can exist in a survey.
func ParseToQuestionType ¶
func ParseToQuestionType(v string) (QuestionType, error)
ParseToQuestionType takes a string and returns the corresponding QuestionType, or an error if the string is invalid.
func (*QuestionType) MarshalJSON ¶
func (s *QuestionType) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*QuestionType) UnmarshalBSONValue ¶
func (s *QuestionType) UnmarshalBSONValue(typ bsontype.Type, raw []byte) error
func (*QuestionType) UnmarshalJSON ¶
func (s *QuestionType) UnmarshalJSON(b []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.