FxForm

public class FxForm<E:Hashable> : FxBase, Sequence

Reactive class that controls binding specific FxField’s to specifc views.

  • List of managed fields.

    Declaration

    Swift

    public var fields: FxFields<E>!
  • Bound fields in proper tab order.

    Declaration

    Swift

    public var tabOrder = [FxField<E>]()
  • Initializes an FxForm.

    let fields = viewModel.setup(contact: contact)
    form = FxForm(fields, viewController: self, scrollView: scrollView)
    

    Declaration

    Swift

    public init(_ fields: FxFields<E>, viewController: UIViewController, scrollView: UIScrollView? = nil)

    Parameters

    fields

    List of fields to be bound.

    viewController

    UIViewController that contains the form and the @IBOutlet’s to be bound to the form.

    scrollView

    UIScrollView to be managed, if any.

  • Convenience method to clear all of a form’s bound fields. Will not clear unbound field values.

    Declaration

    Swift

    public func clear()
  • Returns FxField with the given id. Note that this field is returned from the managed fields list and may not neccesarily be bound to any particular view or control.

    Declaration

    Swift

    public subscript(_ id: E) -> FxField<E>?
  • Returns iterator that will sequence through all bound FxField‘s in tab order.

    Declaration

    Swift

    public func makeIterator() -> FxFormIterator<E>
  • Runs through our list of fields and returns the current responder, if any.

    Declaration

    Swift

    public func currentResponder() -> UIView?
  • Undocumented

    Declaration

    Swift

    public func doneEditing()
  • Gets the current responder and tabs to the next available responder. If none found resigns current responder.

    Declaration

    Swift

    public func tabNext()
  • Gets the current responder and tabs to the next previous responder. If none found resigns current responder.

    Declaration

    Swift

    public func tabPrevious()
  • Adds a hide keyboard tap gesture handler to the specified view.

    form.autoBind()
        .addHideKeyboardGesture()
    

    If no view is specified the gesture is added to the scrollview or if that doesn’t exist, to the view controller’s view.

    Declaration

    Swift

    public func addHideKeyboardGesture(_ view: UIView? = nil) -> FxForm<E>
  • Sets up fields to automatically validate when any change is made.

    Declaration

    Swift

    public func autoValidateOnChange() -> FxForm<E>

    Return Value

    Self for further configuration.

  • Sets up fields to automatically validate when user leaves its associated textfield or any change is made.

    Declaration

    Swift

    public func autoValidateOnChangeOrExit() -> FxForm<E>

    Return Value

    Self for further configuration.

  • Sets up fields to automatically validate when user leaves its associated textfield.

    Declaration

    Swift

    public func autoValidateOnExit() -> FxForm<E>

    Return Value

    Self for further configuration.

  • Undocumented

    Declaration

    Swift

    public func isValid() -> Bool
  • Core function used to bind specific FxField’s to specific views.

    form.bind(.state, .stateTextField)
        .bind(.zip, zipCodeTextField)
        .bind(.text, displayTextField) { _ in return [.viewToField, .error] }
    

    Field values are automatially bound to textfields and other controls using the FxBindableValue protocol.

    Note that the order in which fields are bound controls the tab order.

    Declaration

    Swift

    public func bind(_ id: E, _ view: UIView, _ custom: ((FxField<E>) -> [FxFieldBindings])? = nil) -> FxForm<E>

    Parameters

    id

    Id of FxField to bind.

    view

    Textfield or other control to bind to specified FxField.

    custom

    Optional function which allows custom bindings and/or controlling which bindings are performed automatically.

    Return Value

    Self for additonal bindings or configuration.

  • Convenience method to bind the specified FxField’s error message to a specfifc label.

    form.autoBind()
        .bindError(.zip, zipErrorLabel)
    

    Declaration

    Swift

    public func bindErrorMessage(_ id: E, _ label: UILabel?) -> FxForm<E>

    Parameters

    id

    Id of FxField to bind.

    label

    UILabel to receive message.

    Return Value

    Self for additonal bindings or configuration.

  • Convenience method to bind the specified FxField’s isEnabled flag to a specfifc control.

    form.autoBind()
        .bindIsEnabled(.zip, zipTextField)
    

    Declaration

    Swift

    public func bindIsEnabled(_ id: E, _ view: UIView?) -> FxForm<E>

    Parameters

    id

    Id of FxField to bind.

    label

    Control to receive flag.

    Return Value

    Self for additonal bindings or configuration.

  • Convenience method to bind the specified FxField’s isHidden flag to a specfifc view.

    form.autoBind()
        .bindIsHidden(.zip, zipStackView)
    

    Declaration

    Swift

    public func bindIsHidden(_ id: E, _ view: UIView?) -> FxForm<E>

    Parameters

    id

    Id of FxField to bind.

    label

    View to receive flag.

    Return Value

    Self for additonal bindings or configuration.

  • Convenience method to bind the specified FxField’s title to a specfifc label.

    form.autoBind()
        .bindTitle(.zip, zipLabel)
    

    Declaration

    Swift

    public func bindTitle(_ id: E, _ label: UILabel?) -> FxForm<E>

    Parameters

    id

    Id of FxField to bind.

    label

    UILabel to receive title.

    Return Value

    Self for additonal bindings or configuration.

  • Convenience method to bind the specified FxField’s value to a specfifc button.

    form.autoBind()
        .bindValue(.zip, zipLabel)
    

    Declaration

    Swift

    public func bindValue(_ id: E, _ button: UIButton?) -> FxForm<E>

    Parameters

    id

    Id of FxField to bind.

    label

    UILabel to receive title.

    Return Value

    Self for additonal bindings or configuration.

  • Convenience method to bind the specified FxField’s value to a specfifc label.

    form.autoBind()
        .bindValue(.zip, zipLabel)
    

    Declaration

    Swift

    public func bindValue(_ id: E, _ label: UILabel?) -> FxForm<E>

    Parameters

    id

    Id of FxField to bind.

    label

    UILabel to receive title.

    Return Value

    Self for additonal bindings or configuration.

  • Performs automated binding of managed fields and views.

    This method walks the list of managed fields and searches the view controller’s IBOutlets for views whose names match field.key + suffix.

    If found, the field is automatically bound to that view.

    form.autoBind()
    

    Note that tab order is controlled by IBOutlet order in the UIViewController.

    If a different order is required use autoBind(ids:suffix:custom) or bind fields to views manually.

    Declaration

    Swift

    public func autoBind(_ suffix: String = "Field", _ custom: ((FxField<E>) -> [FxFieldBindings])? = nil) -> FxForm<E>

    Parameters

    suffix

    String appended to field.key for automated matching.

    custom

    Optional function which allows custom bindings and/or controlling which bindings are performed automatically.

    Return Value

    Self for further customization.

  • Performs semi-auotmatic binding of specified fields and views.

    This method finds the matching field for each provided id, then searches the view controller’s IBOutlets for views whose names match field.key + suffix.

    If found, the field is automatically bound to that view.

    form.autoBind(ids: [.firstname, .lastname])
    

    The list order will be the tab order.

    Declaration

    Swift

    public func autoBind(ids: [E], _ suffix: String = "Field", _ custom: ((FxField<E>) -> [FxFieldBindings])? = nil) -> FxForm<E>

    Parameters

    suffix

    String appended to field.key for automated matching.

    custom

    Optional function which allows custom bindings and/or controlling which bindings are performed automatically.

    Return Value

    Self for further customization.

  • Convenience function to automatically change the background color of bound fields if those fields are invalid.

    form.autoBind()
        .autoBindErrorColors()
    

    Methods like this one are useful, but exist more to show what can be done with Rx and a list of managed fields and views.

    Declaration

    Swift

    public func autoBindErrorColors(_ errorColor: UIColor = UIColor(red: 1.0, green: 0.9, blue: 0.9, alpha: 1.0)) -> FxForm<E>

    Parameters

    errorColor

    New background error colors

    Return Value

    Self for further customization.

  • Convenience function to automatically hide the superviews of fields that are hidden.

    form.autoBind()
        .autoBindIsHiddenToSuperviews()
    

    If, for example, your fields are in views with an accompanying label, doing field.isHidden = true would hide the bound view’s parent, hiding both the field and its label.

    Methods like this one are useful, but exist more to show what can be done with Rx and a list of managed fields and views.

    Note: Bind all fields before calling this method.

    Declaration

    Swift

    public func autoBindIsHiddenToSuperviews() -> FxForm<E>

    Return Value

    Self for further customization.

  • Convenience function to automatically bind field titles to specfic labels.

    form.autoBind()
        .autoBindTitles()
    

    This method walks through the list of managed fields and searches the view controller’s IBOutlets for labels whose names match field.key + suffix.‘

    Methods like this one are useful, but exist more to show what can be done with Rx and a list of managed fields and views.

    Note: Bind all fields before calling this method.

    Declaration

    Swift

    public func autoBindTitles(_ suffix: String = "Label") -> FxForm<E>

    Return Value

    Self for further customization.

  • Convenience function to automatically tab to the next field when a field’s max width is reached and the field is valid.

    form.autoBind()
        .autoNext()
    

    This is useful for text entry when the field length is fixed, like a credit card expiration date (12/2014).

    Note: Bind all fields before calling this method.

    Declaration

    Swift

    public func autoNext() -> FxForm<E>

    Return Value

    Self for further customization.

  • Adds the specfied input accessory view to all bound text fields and text views.

    form.autoBind()
        .addInputAccessoryView()
    

    Automatically sets delegate if accessory view conforms to FxInputAccessoryViewInterface.

    Note: Bind all fields before calling this method.

    Declaration

    Swift

    public func addInputAccessoryView(_ view: UIView? = nil) -> FxForm<E>

    Parameters

    view

    The input accessory view.

    Return Value

    Self for further customization.