The most flexible and powerful way to build a form on iOS.
Form came out from our need to have a form that could share logic between our iOS apps and our web clients. We found that JSON was the best way to achieve this.
Form includes the following features:
- Multiple groups: For example, you can have a group for personal details and another one for shipping information
- Field validations: We support
required
,maximum_length
,minimum_length
andformat
(regex). We also support many field types, liketext
,number
,phone_number
,email
,date
,name
and more - Custom sizes: Total
width
is handled as 100% whileheight
is handled in chunks of 85 px - Custom fields: You can register your custom fields, and it's pretty simple (our basic example includes how to make an
image
field) - Formulas or computed values: We support fields that contain generated values from other fields
- Targets:
hide
,show
,update
,enable
,disable
orclear
a field using a target. It's pretty powerful, and you can even set a condition for your target to run - Dropdowns: Generating dropdowns is as easy as adding values to your field, values support
default
flags, targets (in case you want to trigger hiding a field based on a selection), string and numeric values or showing additional info (in case you want to hint the consequences of your selection).
Don't forget to check our Basic Demo for a basic example on how to use Form.
Form works both on the iPhone and the iPad.
This are the required steps to create a basic form with a first name field.
[
{
"id":"group-id",
"title":"Group title",
"sections":[
{
"id":"section-0",
"fields":[
{
"id":"first_name",
"title":"First name",
"type":"name",
"size":{
"width":30,
"height":1
}
}
]
}
]
}
]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Don't forget to set your style, or use the default one if you want
[FORMDefaultStyle applyStyle];
//...
}
- (FORMDataSource *)dataSource
{
if (_dataSource) return _dataSource;
_dataSource = [[FORMDataSource alloc] initWithJSON:self.JSON
collectionView:self.collectionView
layout:self.layout
values:@{@"first_name" : @"Ola"}
disabled:NO];
return _dataSource;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.dataSource = self.dataSource;
}
Targets are one of the most powerful features of form, and we support to hide
, show
, update
, enable
, disable
or clear
a field using a target. You can even set a condition for your target to run!
In the following example we show how to hide or show a field based on a dropdown selection.
[
{
"id":"group-id",
"title":"Group title",
"sections":[
{
"id":"section-0",
"fields":[
{
"id":"employment_type",
"title":"Employment type",
"type":"select",
"size":{
"width":30,
"height":1
},
"values":[
{
"id":0,
"title":"Part time",
"default":true,
"targets":[
{
"id":"bonus",
"type":"field",
"action":"hide"
}
]
},
{
"id":1,
"title":"Full time",
"targets":[
{
"id":"bonus",
"type":"field",
"action":"show"
}
]
}
]
},
{
"id":"bonus",
"title":"Bonus",
"type":"number",
"size":{
"width":30,
"height":1
}
}
]
}
]
}
]
Please check our playbook for guidelines on contributing.
Hyper made this. We're a digital communications agency with a passion for good code, and if you're using this library we probably want to hire you.
Form is available under the MIT license. See the LICENSE.