Form View Controller
Form View Controller is an extension of TableViewController which allows the developer to create complex forms displayed to the user. Form can be validated, or submited accordingly to the needs of the developer.
Form elements can be divided into the groups and sections to make the form more appealing to the eye.
Before the Form will be displayed, on has to call "addRow" method, and pass form element which will conform to "GSDFormCellActionView" protocol:
1 2 3 4 5 6 7
let tempValidation = StringLengthValidation() var tempAction = GSDFormCellTextFieldActionView() _ = tempAction.addValidation(validation: tempValidation, validationMode: ValidationType.onContentChange) tempAction.identifier = "SimpleAction" tempAction.actionLabelTitle = "Simple textfield" tempAction.groupIdentifier = "FirstGroup" self.addRow(actionView: tempAction)
The most important fields of each "GSDFormCellActionView" are: * actionLabelTitle - the title of the row element which will be displayed to the user * identifier - the identifier of the element in the Form. There can be one uniqe identifier per element * groupIdentifier - the identifier of the group to which the element is assigned.
The Form View Controller supports few validation types on different events. Those events are called automatically, on:
- onContentChange - when the value of controlled element will change
- onFocusLost - when the user will exit the contoll after editing it
- onSubmit - when the user will gather all values for submiting the app
To add the validation to specific event one has to create ValidationObject which will conform to "GSDFormCellValidation" protocol. Then he will have to assign that validation object to form element, with specific type of validation.
1 2 3
let tempValidation = StringLengthValidation() var tempAction = GSDFormCellTextFieldActionView() _ = tempAction.addValidation(validation: tempValidation, validationMode: ValidationType.onContentChange)
The default validators are:
- StringtLengthValidation - the validation of length of the string
- EmailValidation - the validation of the provided email adress
- URLValidation - the validation of the url adress
- PESELValidation - the validation of PESEL number
Shwoing and hiding of elements
On different moments developer can show or hide certain elements of his Form. He can do this with functions:
- hideElementWithIdentifier(identifier:String) - it will hide the element with specific identifier
- showElementWithIdentifier(identifier:String) - it will show element with specific identifier
- hideGroupWithIdentifier(identifier:String) - it will hide the group of elements which have the same group identifier
- showGroupWithIdentifier(identifier:String) - it will show the group of elements which have the same group identifier
To get the value of all elements of the form one has to call the "getValues()" function. It will return an array of objects, one for each element of Form