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

    identifier

    A short string that uniquely identifies the input field within the step.

    dataType

    The data type for this input field.

    uiHint

    A UI hint for how the study would prefer that the input field is displayed to the user.

    prompt

    A 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

    DecodingError if the data type field is missing or is not a String.

    Declaration

    Swift

    open class func dataType(from decoder: Decoder) throws -> RSDFormDataType

    Parameters

    decoder

    The decoder used to decode this object.

    Return Value

    The decoded RSDFormDataType data type.

  • Overridable class function for decoding the uiHint from the decoder. The default implementation will key to CodingKeys.uiHint and will check that the ui hint is valid for the given data type.

    Throws

    DecodingError if the uiHint is not a String. RSDValidationError.invalidType if it is not valid for this data type.

    Declaration

    Swift

    open class func uiHint(from decoder: Decoder, for dataType: RSDFormDataType) throws -> RSDFormUIHint?

    Parameters

    decoder

    The decoder used to decode this object.

    dataType

    The 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.range and will decode a range object appropriate to the data type.

    RSDFormDataType.BaseType Type of range to decode
    .integer, .decimal RSDNumberRangeObject
    .date RSDDateRangeObject
    .year RSDDateRangeObject or RSDNumberRangeObject

    Throws

    DecodingError

    Declaration

    Swift

    open class func range(from decoder: Decoder, dataType: RSDFormDataType) throws -> RSDRange?

    Parameters

    decoder

    The decoder used to decode this object.

    dataType

    The data type associated with this instance.

    Return Value

    An appropriate instance of RSDRange or nil if none is present.

  • Overridable class function for decoding the RSDTextFieldOptions from the decoder. The default implementation will key to CodingKeys.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 BaseType of an integer, an instance of RSDTextFieldOptionsObject will be created with a numberPad keyboard type.

    If the data type has a BaseType of a decimal, an instance of RSDTextFieldOptionsObject will be created with a decimalPad keyboard type.

    Throws

    DecodingError

    Declaration

    Swift

    open class func textFieldOptions(from decoder: Decoder, dataType: RSDFormDataType) throws -> RSDTextFieldOptions?

    Parameters

    decoder

    The decoder used to decode this object.

    dataType

    The data type associated with this instance.

    Return Value

    An appropriate instance of RSDTextFieldOptions or nil if 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.surveyRules and will instantiate a list of RSDComparableSurveyRuleObject instances appropriate to the BaseType of the given data type.

    If there isn’t a list keyed to CodingKeys.surveyRules then the decoder will be tested to see if it contains the keys for a RSDComparableSurveyRuleObject instance.

    • example:

    The following will decode as a RSDComparableSurveyRuleObject<String> because of the matchingAnswer 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 the surveyRules 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

    DecodingError

    Declaration

    Swift

    open class func surveyRules(from decoder: Decoder, dataType: RSDFormDataType) throws -> [RSDSurveyRule]?

    Parameters

    decoder

    The decoder used to decode this object.

    dataType

    The data type associated with this instance.

    Return Value

    An array of RSDComparableSurveyRuleObject objects or nil if none are present.

  • Initialize from a Decoder. This decoding method will decode all the properties for this input field.

    Throws

    DecodingError

    Declaration

    Swift

    public required init(from decoder: Decoder) throws

    Parameters

    decoder

    The decoder to use to decode this instance.

  • Encode the object to the given encoder.

    Throws

    EncodingError

    Declaration

    Swift

    public func encode(to encoder: Encoder) throws

    Parameters

    encoder

    The encoder to use to encode this instance.