Library made to cut corners when making complex forms using UITableView.
Add pod DARFormBuilder
to your podfile and run pod install
Framework provides two types of controllers to build forms. One is basic with less abstraction and another one is more feature-packed.
This controller just renders a layout with the cells you provide. You pass it an array of views for them to be rendered in a table. Framework provides a full-featured set of fields that you can use here. You can also pass your own views to be rendered inside the cells.
Example:
let nameField = TextInput()
let titleField = TextInput()
let birthdayField = DateInput()
let likesBoobiesField = SwitchInput()
let tbl = FormTableViewController()
tbl.rows = [
Row(titleField, nameField),
Row(birthdayField),
Row(likesBoobiesField)
]
When using FormTableViewController
you are responsible for validating fields and reacting to field values changes. For validation purposes built-in input classes have an errors
property which will return a list of error messages for a given field. errors
array being empty means that field has passed validation.
Cell for displaying form titles with description. Big font, contrasty color.
let h1 = HeadingLabel(
title: "Flower order",
description: "This is a demonstration of framework capabilities on a case of building flower delivery order form."
)
Cell with label on right or left side . Small font.
Simple textField. Can be limited by max length. Placeholder can be floating.
Date picker. Supports different input modes.
Phone input. Can display only digits.
Label with key and value on the right, left side can contain image.
Label with number dial. Values can be limited by range.
let dialField = KeyNumDialField("Кол-во", value: 2, range: 0..<10)
dialField.onNumberChange = { [weak self] (value: Int) in
// Take this number!
}
Label with switch view on the right and can contain image on the left.
Label with disclosure indicator, can contain image, detail label on left side. Clickable.
Label with image on left side. Clickable.
let selectActionField = SelectFieldWithAction("Choose other")
selectActionField.action = { action in
// Do some action
}
Phone input with button on right side which present contact list. Can display only digits. Clickable.
let selectContact = PhoneInputWithActionButton(placeholder: "Contact", icon: iconImage))
selectContact.presentSelector = { [weak self] viewController in
self?.present(viewController, animated: true, completion: nil)
}
Framework offers a convenient controller for building forms. It is instantiated using a JSON configuration file, which can provide fields configurations, initial values and interaction logic.
Below is a JSON config example:
{
"fields": [
{
"key": "name",
"type": "textInput",
"label": "Name",
"maxLength": 60,
"required": true
},
{
"key": "hideFields",
"type": "switchInput",
"label": "Hide Fields",
"hideFieldsIfChecked": [0]
},
...
],
}
A simple textInput with floating label.
Params:
label: String = ""
— Placeholder/floating label textkeyboardType: String(default|email|phone|number) = "default"
— Keyboard type to display for this fieldmaxLength: Int = 0
— Maximum text lengthrequired: Bool = false
— Field will not pass validation if text is not present
Date input with floating label.
Params:
label: String = ""
— Placeholder/floating label textinputMode: String(datetime|date|time) = "datetime"
— Date input mode to display for this fielddisplayFormat: String = "dd.MM.yyyy"
— Display date format in unicode format patternvalueFormat: String = “yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX”
— Field value format in unicode format patternrequired: Bool = false
— Field will not pass validation if text is not present
Phone input with floating label.
Params:
label: String = ""
— Placeholder/floating label textdisplayFormat: String = "+7 ### ###-##-##"
— Phone number formatting maskpickFromContacts: Bool = false
— Display pick from contacts button on the fieldrequired: Bool = false
— Field will not pass validation if text is not present
Switch with label on the left.
Params:
label: String = ""
— Label texthideFieldsIfChecked: [Int] = []
— Form should hide fields at given indices if the switch is on
This framework is built and maintained by DAR Team. Please check out our products!