FUITextFieldFormCell

@IBDesignable
open class FUITextFieldFormCell : FUIInlineValidationTableViewCell, FUIPropertyFormCell, UITextFieldDelegate

The reusable UI component implemented as an UITableViewCell to display or edit a key-value pair property.

FUISimplePropertyFormCell

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

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

And an onChangeHandler:

  • onChangeHandler: a handler closure, which is invoked on changes to the value

Optionally, the developer may provide

  • isEditable: Indicates if the cell’s value may be modified. Defaults to true. When the cell is editable, the key and value are arranged vertically in a stack, otherwise they are arranged horizontally.

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

  • isAlternativeInputEnabled: A Bool that shoes or hides the alternativeInputButton. This button will show if isAlternativeInputEnabled and isEditable are true.

Color settings:

Setting tintColor for add button for a state using setTintColor(_:for:) api. Currently disabled and normal are supported.

 cell.setTintColor(UIColor.red, for: .normal)

Remark

The font-color attribute will be overridden by tint-color-disabled attribute when cell is switched to disabled state. DO NOT set textColor for valueTextView when cell is in disabled state! Use the setTintColor(UIColor(), for: .disabled) to set the color.

The following is an example of usage in an application UITableViewController:

Important

The app’s UITableViewController must subclass FUIFormTableViewController
override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.register(FUITextFieldFormCell.self, forCellReuseIdentifier: FUITextFieldFormCell.reuseIdentifier)
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: FUITextFieldFormCell.reuseIdentifier, for: indexPath) as! FUITextFieldFormCell

    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_keyLabel {}
 fdlFUITextFieldFormCell_valueTextField {}

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 default cell reuse identifier.

    Declaration

    Swift

    open class var reuseIdentifier: String { get }
  • The value type is String.

    Declaration

    Swift

    public typealias ValueType = String
  • The value of the property.

    Declaration

    Swift

    @IBInspectable
    public var value: String { get set }
  • Method determining the type of presented keyboard

    Declaration

    Swift

    public var keyboardType: UIKeyboardType { get set }
  • Implementation of change handler. Is invoked on changes to the value property.

    Declaration

    Swift

    public var onChangeHandler: ((String) -> Void)?
  • Indicates if the value of the cell could be changed or not. For FUISimplePropertyFormCell this property is always false.

    Declaration

    Swift

    public var isEditable: Bool { get set }
  • isEnabled and isEditable are in sync.

    Declaration

    Swift

    override public var isEnabled: Bool { get set }
  • The key name of the property.

    Declaration

    Swift

    @IBInspectable
    public var keyName: String? { get set }
  • The UILabel holds the key name string.

    Declaration

    Swift

    @IBOutlet
    public private(set) weak var keyLabel: UILabel!
  • The UITextField holds the value string.

    Declaration

    Swift

    @IBOutlet
    public private(set) weak var valueTextField: UITextField!
  • If isTrackingLiveChanges == true, then onChangeHandler will be invoked for every letter entered. Otherwise, onChangeHandler will be invoked only after user taps Done key, or the field resigns first responder.

    Defaults to false.

    Declaration

    Swift

    public var isTrackingLiveChanges: Bool
  • The placeholder text for the value text field.

    Declaration

    Swift

    @IBInspectable
    public var placeholderText: String? { get set }
  • The formatter for the UITextField in this cell.

    Currently, SAPFiori provides two implementations:

    Declaration

    Swift

    public var formatter: FUIFormattedStringEditing? { get set }
  • A FUIButton for an alternative text entry method. Implement the didSelectHandler to manage alternative entry. Also, supply an image to display on the button.

    Declaration

    Swift

    public let alternativeInputButton: FUIButton
  • A Bool to enable alternative entry. The cell must also have isEditable set to true to display the button. The button will hide while text entry is in progress. The default value is false.

    Declaration

    Swift

    public var isAlternativeInputEnabled: Bool { get set }