FUITextFieldCollectionViewCell

@MainActor
open class FUITextFieldCollectionViewCell : FUIInlineValidationDrawingCollectionViewCell<FUITextFieldContentView>, FUIFormCell

The reusable UI component implemented as a UICollectionViewCell to display or edit a textfield.

The developer should set the following properties on the cell in their implementation of the UITableViewDataSource cellForRow(at:) function:

  • keyName: The key name of the property.
  • value: The value of the property.

And, an onChangeHandler:

  • onChangeHandler: a handler closure that is invoked on changes to the value.

Optionally, the developer may provide

  • isEditable: Indicates whether the cell’s value may be modified. The default is true.

  • isStacked: A Boolean value to determine whether the cell should use a stacked or linear layout. If the device’s accessibility settings font size is increased, the cell will force a stacked layout. By default, this property is set to true.

  • maxKeyWidth: The maximum width of the key with a linear layout. By default, the width is 115 for compact and 160 for regular. The set value must meet the minimum default threshold.

  • alternativeInputButton: An FUIButton that manages an alternative method to fill the textField.

  • isAlternativeInputEnabled: A Bool that shows or hides the alternativeInputButton. This button will indicate whether isAlternativeInputEnabled and isEditable are true.

Color settings:

Manage the color of the control by programmatically setting the textColor and tintColor.

The following is an example of usage in an application with UIViewController and UICollectionViewDataSource:

override func viewDidLoad() {
    super.viewDidLoad()
    self.collectionView.register(FUITextFieldCollectionViewCell.self, forCellReuseIdentifier: FUITextFieldCollectionViewCell.reuseIdentifier)
}

override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: FUITextFieldCollectionViewCell.reuseIdentifier, for: indexPath) as! FUITextFieldCollectionViewCell

    cell.keyName = "Editable"
    cell.value = myObject.productName

    // MARK:  implement onChangeHandler
    cell.onChangeHandler = { newValue in
        myObject.productName = newValue
    }

    // MARK: Implement alternative input, i.e. use OCR to capture input

    cell.isAlternativeInputEnabled = true
    let inputImage = FUIIconLibrary.system.camera
    cell.alternativeInputButton.setImage(inputImage.withRenderingMode(.alwaysTemplate), for: .normal)
    cell.alternativeInputButton.didSelectHandler = { [weak self, weak cell] (button) in

        //Import SAPML to use OCR capability
        let textRecController = FUITextRecognitionViewController()
        textRecController.recognitionView.observationHandler = { [unowned textRecController] observations in
            let filteredObservations = <#filter out unwanted text#>
            textRecController.recognitionView.showTexts(for: filteredObservations)
            let areObservationsValid = <#filteredObservations meets desired criteria#>
            if areObservationsValid {
                DispatchQueue.main.async {
                    cell?.value = filteredObservations.map { $0.value }.joined(separator:" ")
                }
                return true
            }
            return false
        }

        textRecController.onClose = {
            self?.dismiss(animated: true)
        }
        self?.present(UINavigationController(rootViewController: textRecController), animated: true)
    }

    return cell
 }

## Theming

nuiClass:

 fdlFUITextFieldFormCell {}

Supported TEXT class paths:

 fdlFUITextFieldFormCell_keyText {}
 fdlFUITextFieldFormCell_valueText {}

Supported TEXT properties:

 font-color: Color;
 placeholder-color: Color;
 font-style: UIFontTextStyle;

Supported BUTTON class paths:

 fdlFUITextFieldFormCell_alternativeInputButton {}

Supported BUTTON properties:

 background-color: Color;
 font-color: Color;
  • The key name of the property.

    Declaration

    Swift

    @MainActor
    open var keyName: String? { get set }
  • The FUITextField holds the value string.

    Declaration

    Swift

    @MainActor
    open var valueTextField: FUITextField { get }
  • A Boolean value to determine whether the cell should use a stacked or linear layout.

    Declaration

    Swift

    @MainActor
    open var isStacked: Bool { get set }
  • The maximum width of the key with a linear layout. By default, the width is 115 for compact and 160 for regular. The set value must meet the minimum default threshold.

    Declaration

    Swift

    @MainActor
    open var maxKeyWidth: CGFloat { get set }
  • An FUIButton for an alternative text entry method. Implement the didSelectHandler to manage the alternative text entry. Also, supply an image to display on the button.

    Declaration

    Swift

    @MainActor
    open var alternativeInputButton: FUIButton { get }
  • Indicates whether the value of the cell can be changed or not. For FUISimplePropertyFormCell this property is always false.

    Declaration

    Swift

    @MainActor
    open var isEditable: Bool { get set }
  • A Bool to enable alternative text entry. The cell must also have isEditable set to true to display the button. The button will be hidden while text entry is in progress. The default value is false.

    Declaration

    Swift

    @MainActor
    open var isAlternativeInputEnabled: Bool { get set }
  • isEnabled and isEditable are in sync.

    Declaration

    Swift

    @MainActor
    open override var isEnabled: Bool { get set }
  • This is the maximum length of the text if maxTextLength is greater than 0.

    If the text length reaches this limit when isCharCountEnabled is false, the user cannot enter more text. Note: If the user pastes a string and the length plus the current text length is greater than the limit, the insert is rejected. Partial strings are not accepted in the text field.

    If the text length reaches this limit when isCharCountEnabled is true, the user cannot enter more text if allowsBeyondLimit is false. In the case where allowsBeyondLimit is true, the user can enter more text beyond the limitation in the error state.

    The default value for maxTextLength is 0, which means no limit.

    Declaration

    Swift

    @MainActor
    public var maxTextLength: Int { get set }
  • The value of the property.

    Declaration

    Swift

    @MainActor
    open var value: String { get set }
  • The error message when the character count limitation is reached.

    Declaration

    Swift

    @MainActor
    public var charCountReachLimitMsg: String { get set }
  • The error message when the character count exceeds the limitation.

    Declaration

    Swift

    @MainActor
    public var charCountBeyondLimitMsg: String { get set }
  • Implementation of the change handler. This is invoked on changes to the value property.

    Declaration

    Swift

    @MainActor
    open var onChangeHandler: ((String) -> Void)? { get set }
  • The placeholder text for the value text field.

    Declaration

    Swift

    @available(*, deprecated, message: "This property is deprecated.  Please use `placeholder.text`.")
    @MainActor
    open var placeholderText: String? { get set }
  • Method for determining the type of the presented keyboard.

    Declaration

    Swift

    @MainActor
    open var keyboardType: UIKeyboardType { get set }
  • The formatter for the UITextField in this cell.

    Currently, SAPFiori provides two implementations:

    Declaration

    Swift

    @MainActor
    open var formatter: FUIFormattedStringEditing? { get set }
  • If isTrackingLiveChanges == true, then onChangeHandler will be invoked for every letter entered. Otherwise, onChangeHandler will be invoked only after the user taps the Done key, or the field resigns as first responder.

    The default value is false.

    Declaration

    Swift

    @MainActor
    open var isTrackingLiveChanges: Bool { get set }
  • The customized text alignment for the valueTextField.

    If this property is nil, the default alignment is used.

    • For left-to-right languages and the cell is editable, the default is left-aligned.
    • For left-to-right languages and the cell is not editable, the default is right-aligned.
    • For righ to left languages and the cell is editable, the default is rignt aligned.
    • For right-to-left languages and the cell is not editable, the default is left-aligned.

    Declaration

    Swift

    @MainActor
    open var valueTextAlignment: NSTextAlignment? { get set }
  • The hint text.

    Declaration

    Swift

    @MainActor
    open var hintText: String? { get set }
  • Indicates whether the cell is read-only or not.

    The default value is false.

    Declaration

    Swift

    @MainActor
    open var isReadOnly: Bool { get set }
  • Indicates whether the cell is a mandatory field.

    The default value is false.

    Declaration

    Swift

    @MainActor
    open var isRequired: Bool { get set }
  • Indicates that the cell is a mandatory field.

    The default value is *.

    Declaration

    Swift

    @MainActor
    public var mandatoryIndicator: FUIText { get set }
  • Indicates whether to hide the read-only hint or not.

    A default hint is provided when this cell’s isReadOnly is true unless this property is true. The default is false, meaning that the default read-only hint will be shown when isReadOnly is true.

    Declaration

    Swift

    @MainActor
    open var hidesReadOnlyHint: Bool { get set }
  • Declaration

    Swift

    @MainActor
    public override var validationMessage: String? { get set }
  • Declaration

    Swift

    @MainActor
    public override var inlineValidationStyle: FUIInlineValidationStyle { get set }
  • Message type of FUIInlineValidationView.

    Declaration

    Swift

    @MainActor
    public override var inlineValidationType: FUIInlineValidationType { get set }
  • If isCharCountEnabled is true, it will show the character count and the maxValueTextLength. The character count number will be updated during editing.

    The default value is false.

    Declaration

    Swift

    @MainActor
    public var isCharCountEnabled: Bool { get set }
  • If showsErrorInValidationMsg is true, it will show the character count error message in the validationMessage of the FUITextFieldFormCell. Otherwise, the error message will be shown in the errorView in the same layout as the hintView.

    The default is true.

    Declaration

    Swift

    @MainActor
    public var showsErrorInValidationMsg: Bool { get set }
  • If allowsBeyondLimit is true, it will allow the user to input continuously even after maxValueTextLength is reached. It will be in an error state with an error message and a semantic negative color. If allowsBeyondLimit is false, it will auto-stop user input when maxValueTextLength is reached.

    The default value is false.

    Declaration

    Swift

    @MainActor
    public var allowsBeyondLimit: Bool { get set }
  • The error text.

    Declaration

    Swift

    @MainActor
    open var errorText: String? { get set }
  • If hasError is true, it will be in an error state with an error message and a semantic negative color.

    The default value is false.

    Declaration

    Swift

    @MainActor
    public var hasError: Bool { get set }
  • A Bool to indicate whether there is a character counting error. When it is true, the input character count exceeds the maxTextLength.

    Declaration

    Swift

    @MainActor
    public var hasCharCountError: Bool { get }