RSDInputFieldObject
open class RSDInputFieldObject : RSDSurveyInputField, Codable
RSDInputFieldObject is a Decodable implementation of the RSDSurveyInputField protocol. This is implemented as
an open class so that the decoding strategy can be used to support subclasses.
-
A short string that uniquely identifies the input field within the step. The identifier is reproduced in the results of a step result in the step history of a task result.
Declaration
Swift
public let identifier: String -
The data type for this input field. The data type can have an associated ui hint.
Declaration
Swift
open private(set) var dataType: RSDFormDataType -
A UI hint for how the study would prefer that the input field is displayed to the user.
Declaration
Swift
open private(set) var uiHint: RSDFormUIHint? -
A localized string that displays a short text offering a hint to the user of the data to be entered for this field. This is only applicable for certain types of UI hints and data types.
Declaration
Swift
open var prompt: String? -
A localized string that displays placeholder information for the input field.
You can display placeholder text in a text field or text area to help users understand how to answer the item’s question.
Declaration
Swift
open var placeholder: String? -
Options for displaying a text field. This is only applicable for certain types of UI hints and data types.
Declaration
Swift
open var textFieldOptions: RSDTextFieldOptions? -
A range used by dates and numbers for setting up a picker wheel, slider, or providing text field input validation. This is only applicable for certain types of UI hints and data types.
Declaration
Swift
open var range: RSDRange? -
A Boolean value indicating whether the user can skip the input field without providing an answer.
Declaration
Swift
open var isOptional: Bool = false -
A list of survey rules associated with this input field.
Declaration
Swift
open var surveyRules: [RSDSurveyRule]? -
A formatter that is appropriate to the data type. If
nil, the format will be determined by the UI. This is the formatter used to display a previously entered answer to the user or to convert an answer entered in a text field into the appropriate value type.Declaration
Swift
open var formatter: Formatter? -
Default intializer.
Declaration
Swift
public init(identifier: String, dataType: RSDFormDataType, uiHint: RSDFormUIHint? = nil, prompt: String? = nil)Parameters
identifierA short string that uniquely identifies the input field within the step.
dataTypeThe data type for this input field.
uiHintA UI hint for how the study would prefer that the input field is displayed to the user.
promptA localized string that displays a short text offering a hint to the user of the data to be entered for this field.
-
Validate the input field to check for any configuration that should throw an error.
Declaration
Swift
open func validate() throws -
Overridable class function for decoding the data type from the decoder. The default implementation will key to
CodingKeys.dataType.Throws
DecodingErrorif the data type field is missing or is not aString.Declaration
Swift
open class func dataType(from decoder: Decoder) throws -> RSDFormDataTypeParameters
decoderThe decoder used to decode this object.
Return Value
The decoded
RSDFormDataTypedata type. -
Overridable class function for decoding the uiHint from the decoder. The default implementation will key to
CodingKeys.uiHintand will check that the ui hint is valid for the given data type.Throws
DecodingErrorif the uiHint is not aString.RSDValidationError.invalidTypeif it is not valid for this data type.Declaration
Swift
open class func uiHint(from decoder: Decoder, for dataType: RSDFormDataType) throws -> RSDFormUIHint?Parameters
decoderThe decoder used to decode this object.
dataTypeThe data type associated with this instance.
Return Value
The UI Hint associated with this input field (if any).
-
Overridable class function for decoding the range from the decoder. The default implementation will key to
CodingKeys.rangeand will decode a range object appropriate to the data type.RSDFormDataType.BaseType Type of range to decode .integer, .decimal RSDNumberRangeObject.date RSDDateRangeObject.year RSDDateRangeObjectorRSDNumberRangeObjectThrows
DecodingErrorDeclaration
Swift
open class func range(from decoder: Decoder, dataType: RSDFormDataType) throws -> RSDRange?Parameters
decoderThe decoder used to decode this object.
dataTypeThe data type associated with this instance.
Return Value
An appropriate instance of
RSDRangeornilif none is present. -
Overridable class function for decoding the
RSDTextFieldOptionsfrom the decoder. The default implementation will key toCodingKeys.textFieldOptions. If no text field options are defined in the decoder, then for certain data types, the default keyboard type is instantiated.If the data type has a
BaseTypeof aninteger, an instance ofRSDTextFieldOptionsObjectwill be created with anumberPadkeyboard type.If the data type has a
BaseTypeof adecimal, an instance ofRSDTextFieldOptionsObjectwill be created with adecimalPadkeyboard type.Throws
DecodingErrorDeclaration
Swift
open class func textFieldOptions(from decoder: Decoder, dataType: RSDFormDataType) throws -> RSDTextFieldOptions?Parameters
decoderThe decoder used to decode this object.
dataTypeThe data type associated with this instance.
Return Value
An appropriate instance of
RSDTextFieldOptionsornilif none is present. -
Overridable class function for decoding a list of survey rules from the decoder for this instance. The default implementation will check the container for a keyed array using
CodingKeys.surveyRulesand will instantiate a list ofRSDComparableSurveyRuleObjectinstances appropriate to theBaseTypeof the given data type.If there isn’t a list keyed to
CodingKeys.surveyRulesthen the decoder will be tested to see if it contains the keys for aRSDComparableSurveyRuleObjectinstance.- example:
The following will decode as a
RSDComparableSurveyRuleObject<String>because of thematchingAnswer
key.```` { "identifier": "foo", "prompt": "Text", "placeholder": "enter text", "dataType": "singleChoice.string", "choices" : ["never", "sometimes", "often", "always"], "matchingAnswer": "never" } ````The following will decode as an array of
[RSDComparableSurveyRuleObject<Int>]because of thesurveyRules
key.```` { "identifier": "foo", "dataType": "integer", "uiHint": "slider", "range" : { "minimumValue" : -2, "maximumValue" : 3, "stepInterval" : 1, "unit" : "feet" }, "surveyRules" : [ { "skipToIdentifier": "lessThan", "ruleOperator": "lt", "matchingAnswer": 0 }, { "skipToIdentifier": "greaterThan", "ruleOperator": "gt", "matchingAnswer": 1 } ] } ````Throws
DecodingErrorDeclaration
Swift
open class func surveyRules(from decoder: Decoder, dataType: RSDFormDataType) throws -> [RSDSurveyRule]?Parameters
decoderThe decoder used to decode this object.
dataTypeThe data type associated with this instance.
Return Value
An array of
RSDComparableSurveyRuleObjectobjects ornilif none are present. -
Initialize from a
Decoder. This decoding method will decode all the properties for this input field.Throws
DecodingErrorDeclaration
Swift
public required init(from decoder: Decoder) throwsParameters
decoderThe decoder to use to decode this instance.
-
Encode the object to the given encoder.
Throws
EncodingErrorDeclaration
Swift
public func encode(to encoder: Encoder) throwsParameters
encoderThe encoder to use to encode this instance.
View on GitHub
RSDInputFieldObject Class Reference