/Form

The most flexible and powerful way to build a form on iOS

Primary LanguageObjective-COtherNOASSERTION

Form logo

Version License Platform Join the chat at https://gitter.im/hyperoslo/Form

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, max_length, min_length, min_value, max_value and format (regex). We also support many field types, like text, number, phone_number, email, date, name and more
  • Custom sizes: Total width is handled as 100% while height 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 or clear 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).

Form works both on the iPhone and the iPad.

You can try one of our demos by running this command in your Terminal:

pod try Form

Usage

Basic Form

This are the required steps to create a basic form with a first name field.

Form

JSON

[
  {
    "id":"group-id",
    "title":"Group title",
    "sections":[
      {
        "id":"section-0",
        "fields":[
          {
            "id":"first_name",
            "title":"First name",
            "type":"name",
            "size":{
              "width":30,
              "height":1
            }
          }
        ]
      }
    ]
  }
]

In your iPad app

AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Don't forget to set your style, or use the default one if you want
    [FORMDefaultStyle applyStyle];

    //...
}

Subclass

Make sure that your UICollectionViewController is a subclass of FORMViewController.


Targets

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.

Targets

JSON

[
  {
    "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
            }
          }
        ]
      }
    ]
  }
]

Installation

Form is available through CocoaPods. To install it, simply add the following line to your Podfile:

use_frameworks!

pod 'Form'

Contributing

Please check our playbook for guidelines on contributing.

Credits

Hyper made this. We’re a digital communications agency with a passion for good code and delightful user experiences. If you’re using this library we probably want to hire you (we consider remote employees too, the only requirement is that you’re awesome).

License

Form is available under the MIT license. See the LICENSE.