The FormKit API includes a set of UITableViewCells
which should be used in the Fiori Design Language for constructing table views for creating or editing business objects, or for building filter controls. Each cell implements the FUIFormCell
protocol and invokes an optional onChangeHandler
closure to handle value changes.
FormKit cells are used in Filter and Create Floorplans.
Interface
All cells in FormKit
implement the FUIFormCell
protocol. FUIFormCell
is generic for its value
property, and has an associatedtype
: ValueType
, which allows the value to be accessed with type safety.
FUITitleFormCell - displays the title of the form. The cell can be marked as editable to allow user editing of the title (for example, the Work Request
cell in the above image):
let cell = tableView.dequeueReusableCell(withIdentifier: FUITitleFormCell.reuseIdentifier, for: indexPath) as! FUITitleFormCell
cell.value = "Work Request"
cell.isEditable = false
return cell
FUINoteFormCell - the user can enter notes in the cell (for example, the cell between Work Request
and Location
in the above image):
let cell = tableView.dequeueReusableCell(withIdentifier: FUINoteFormCell.reuseIdentifier, for: indexPath) as! FUINoteFormCell
cell.delegate = self
cell.placeholder = "Please type something"
cell.responderDelegate = self
cell.cellHeight = 80
return cell
FUISimplePropertyFormCell - provides a key/value pair that displays the key and value of the cell. The value of the cell cannot be modified (for example, the Request ID
cell in the above image):
// An un-editable property cell
let cell = tableView.dequeueReusableCell(withIdentifier: FUISimplePropertyFormCell.reuseIdentifier, for: indexPath) as! FUISimplePropertyFormCell
cell.key = "Request ID"
cell.value = "#201611-001234"
cell.delegate = self
return cell
FUIListPickerFormCell - provides a key/value pair that displays the key and value of the cell. For single selection, set its allowsMultipleSelection property to false:
// A property cell with list picker
let cell = tableView.dequeueReusableCell(withIdentifier: FUIListPickerFormCell.reuseIdentifier, for: indexPath) as! FUIListPickerFormCell
cell.keyName = "Work Group"
cell.value = [0]
cell.delegate = self
cell.valueOptions = ["Construction", "Repair", "Engineering", "Vendor"]
cell.allowsMultipleSelection = false
cell.valueTextField.text = descriptionForSelectedStrings(cell.valueOptions, at: propValue3)
return cell
When this cell is selected, a table view displays the available options for the user to choose:
A FUIListPickerFormCell
can also be set as multiple selectable in the app by setting its allowsMultipleSelection
property to true as follows in the UITableViewController
:
let valueOptions12 = ["One", "Two", "Three", "Four", "Five", "Six", "Seven"]
var propValue12 = [1, 3, 6]
//...
// A property cell with list picker
let cell = tableView.dequeueReusableCell(withIdentifier: FUIListPickerFormCell.reuseIdentifier, for: indexPath) as! FUIListPickerFormCell
cell.keyName = "Choose Multiple"
cell.value = propValue12
cell.valueOptions = valueOptions12
// Developer is responsible to set the text of the valueTextField of the FUIListPickerFormCell.
// Here, function descriptionForSelectedStrings is just returns the
// comma separated selected string.
cell.valueTextField.text = descriptionForSelectedStrings(valueOptions12, at: propValue12)
cell.allowsMultipleSelection = true
cell.listPicker.prompt = "Please select multiple items"
cell.delegate = self
return cell
And when the cell is tapped, a multiple select table with specified optional values is displayed:
Developer could customize the cells displayed in the selection table by setting the dataSource
property of the listPicker
property of the FUIListPickerFormCell
, as described below:
let propKey11 = "List Picker with Object Cells"
var propValue11: [Int] = []
// ObjectCellListPickerDataSource implements ListPickerDataSource and ListPickerSearchResultsUpdating
let listPickerDataSource11 = ObjectCellListPickerDataSource(40)
// ...
// A FUIListPickerFormCell with FUIObjectTableViewCell
let cell = tableView.dequeueReusableCell(withIdentifier: FUIListPickerFormCell.reuseIdentifier, for: indexPath) as! FUIListPickerFormCell
cell.keyName = propKey11
cell.value = propValue11
cell.valueTextField.text = listPickerDataSource11.descriptionForSelectedItems(at: propValue11)
cell.listPicker.dataSource = listPickerDataSource11
cell.listPicker.searchResultsUpdating = listPickerDataSource11
cell.listPicker.prompt = "Please select multiple items"
cell.listPicker.register(FUIObjectTableViewCell.self, forCellReuseIdentifier: FUIObjectTableViewCell.reuseIdentifier)
cell.allowsMultipleSelection = true
cell.allowsEmptySelection = true
cell.delegate = self
cell.delegate = self
return cell
And when the cell is tapped, a multiple select table with FUIObjectTableViewCell is displayed:
A search bar could be added to the FUIListPickerFormCell
in the selection table view by setting the isSearchEnabled
, dataSource
and listPickerResultsUpdating
. Optionally, a barcode scanner could be added to the search bar by setting the isBarcodeScannerEnabled
property of the searchBar
property, as follows:
let propKey7 = "Choose Multiple"
var propValue7: [Int] = []
let listPickerDataSource7 = StringListPickerDataSource(options: ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen"])
// ...
let cell = tableView.dequeueReusableCell(withIdentifier: FUIListPickerFormCell.reuseIdentifier, for: indexPath) as! FUIListPickerFormCell
cell.keyName = propKey7
cell.value = propValue7
cell.allowsMultipleSelection = true
cell.allowsEmptySelection = false
cell.valueTextField.text = descriptionForSelectedStrings(cell.valueOptions, at: propValue7)
cell.listPicker.dataSource = listPickerDataSource7
cell.listPicker.searchResultsUpdating = listPickerDataSource7
cell.listPicker.prompt = "Please select multiple items"
cell.listPicker.isSearchEnabled = true
cell.delegate = self
cell.listPicker.searchBar?.isBarcodeScannerEnabled = true
cell.listPicker.searchBar?.barcodeScanner?.scanMode = .ean_upc
cell.listPicker.searchBar?.barcodeScanner?.scanResultTransformer = { (scanString) -> String in
return self.transformStringToSearchBar(scanResultString: scanString)
}
return cell
When the cell is tapped, the multiple selection table is shown with a search bar under the navigation bar.
When user starts typing in the search bar, the displayed list will be filtered.
When the barcode scanner icon is tapped, the barcode scan view is displayed. Note that the barcode scanner icon will not be displayed when the device does not support camera, such as running on simulator. The icon will not be displayed when the search bar is active, also.
FUIDatePickerFormCell - provides a key/value pair that displays a key and a Date as the property value. When this cell is selected, a UIDatePicker displays to allow the user to select a date. The app can provide a DateFormatter to customize how the date displays (for example, the Appointment Date
cell in the above image):
let cell = tableView.dequeueReusableCell(withIdentifier: FUIDatePickerFormCell.reuseIdentifier, for: indexPath) as! FUIDatePickerFormCell
cell.key = "Appointment Date"
cell.date = Date()
// if the date property is not provided, the default value is now.
cell.delegate = self
return cell
FUIDurationPickerFormCell - provides a key/value pair that displays a key and a TimeInterval as the property value. When this cell is selected, a UIDatePicker displays to allow the user to select a duration. The app can provide a text formatter to customize how the duration displays (for example, the formatter by default is %d Hrs %d Min
):
let cell = tableView.dequeueReusableCell(withIdentifier: FUIDurationPickerFormCell.reuseIdentifier, for: indexPath) as! FUIDurationPickerFormCell
cell.keyName = "Duration"
cell.value = 3600 //In seconds
cell.delegate = self
return cell
FUISwitchFormCell - the property for this cell is a boolean value that uses a standard UISwitch to display the value. The user can change the value by tapping the switch (for example, the Confirmed
cell in the above image):
// A FUISwitchFormCell
let cell = tableView.dequeueReusableCell(withIdentifier: FUISwitchFormCell.reuseIdentifier, for: indexPath) as! FUISwitchFormCell
cell.key = "Confirmed"
cell.value = true
cell.delegate = self
return cell
AttachmentFormCell - a cell to which photos or selected files from the photo library can be added as attachments:
let cell = tableView.dequeueReusableCell(withIdentifier: AttachmentFormCell.reuseIdentifier, for: indexPath) as! AttachmentFormCell
cell.attachmentDelegate = attachmentDelegate
return cell
The application needs to add the following to its info.plist in order to access camera and photo library:
<key>NSCameraUsageDescription</key>
<string>Please permit access to camera</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>Please permit access to photo library</string>
Each
UITableViewController
is allowed to have only oneAttachmentFormCell
.
FUISegmentedControlFormCell - A type of FUIPropertyFormCell
, representing a key/value pair of the cell. The user can select a value by clicking the button. The cell is editable by default and can be set to isEditable
to disable user interaction.
Usage
Implement a UITableViewController
that hosts the cells and constructs a Create Window view similar to the one in the example above:
The UITableViewController must subclass FUIFormTableViewController
.
class MyFormTableViewController: FormTableViewController {
...
}
Register the reuse identifiers of all needed FUIFormCell
s, and enable auto-dimension row height calculation.
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(FUITitleFormCell.self, forCellReuseIdentifier: FUITitleFormCell.reuseIdentifier)
...
self.tableView.estimatedRowHeight = 200
self.tableView.rowHeight = UITableViewAutomaticDimension
}
Reuse the registered cells in tableView(_:cellForRowAt:)
, and bind the form data to the cell views:
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// An simple key-value property cell
let cell = tableView.dequeueReusableCell(withIdentifier: FUISimplePropertyFormCell.reuseIdentifier, for: indexPath) as! FUISimplePropertyFormCell
cell.key = "Location"
cell.value = "127 Higgins Drive, Palo Alto"
// MARK: Implement `onChangeHandler` closure to process the new value entered by the user
cell.onChangeHandler = { newValue in
myObject.value = newValue
}
return cell
}
For AttachmentFormCell
, set the cell delegate
property to DefaultAttachmentFormCellDelegate
, or implement the didAddAttachment(attachment:)
and didDeleteAttachment(attachmentNumber:)
functions of AttachmentFormCellDelegate
protocol, to receive notifications when attachments are added or deleted by the user:
public class DefaultAttachmentFormCellDelegate: AttachmentFormCellDelegate {
/**
The list of attachments.
*/
public var attachmentList: [AttachmentData] = [AttachmentData]()
public init() {}
}
public func didAddAttachment(attachment: AttachmentData) {
attachmentList.append(attachment)
}
public func didDeleteAttachment(attachmentNumber: Int) {
var index = -1
for i in 0..<attachmentList.count {
if attachmentList[i].attachmentNumber == attachmentNumber {
index = i
break
}
}
if index != -1 {
attachmentList.remove(at: index)
}
}