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

Related tags

Form Form
Overview

Form logo

Version License Platform Gitter

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, count, segment, switch, 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 iOS 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
            }
          }
        ]
      }
    ]
  }
]

Group Collapsibility

Groups have two JSON based collapsibility options: collapsed and collapsible

The collapsed option accepts true or false and defines the default state for the group it is added to. The default is false.

The collapsible option also accepts true or false but defines whether or not a group can be collapsed at all. Defining this option as false, prevents a group from being collapsed on click or with collapseAllGroupsForCollectionView. The default is true.

In your application code, you can also call collapseAllGroupsForCollectionView on the data source to collapse all groups in a collection view.

Counter Fields

To make quick and easy integer adjustments without popping up a keyboard, you can use the count field. It works just like a number field but provides a minus button in the UITextField's leftView and a plus button in the rightView. A tap on either will decrease or increase, respectively, the number by a value of one.

Example JSON

{
  "groups":[
    {
      "id":"counter",
      "title":"Counter Example",
      "sections":[
        {
          "id":"counter-example",
          "fields":[
            {
              "id":"guests",
              "title":"Present Guests",
              "info":"Press minus to decrease, plus to increase",
              "type":"count",
              "value":0,
              "size":{
                "width":25,
                "height":1
              },
              "validations":{
                "required":true,
                "min_value":0,
                "max_value":100
              }
            }
          ]
        }
      ]
    }
  ]
}

Segment Fields

Segment fields can be used in place of text or select fields where the options are known and limited. Since segment fields do not require multiple taps or keyboard entry, data can be recorded quickly and easily with a single click. The segment field type allows for multiple values like the select field type and supports many of the same attributes.

Example JSON

{
  "groups":[
    {
      "id":"group1",
      "title":"Segment Example",
      "sections":[
        {
          "id":"section1",
          "fields":[
            {
              "id":"location",
              "title":"Work Location",
              "type":"segment",
              "styles":{
                "font":"AvenirNext-DemiBold",
                "font_size":"16.0",
                "tint_color":"#CBEDBF"
              },
              "values":[
                {
                  "id":"in_house",
                  "title":"In-house",
                  "info":"In-house employee",
                  "default":true,
                },
                {
                  "id":"remote",
                  "title":"Remote",
                }
              ],
              "size":{
                "width":50,
                "height":1
              }
            }
          ]
        }
      ]
    }
  ]
}

Switch Fields

Switch fields can be used where a true or false response is desired. The switch field type allows for a single value of 0, false, 1, or true. Background and tint color styles are also available for this field.

Example JSON

{
  "groups":[
    {
      "id":"group1",
      "title":"Switch Example",
      "sections":[
        {
          "id":"section1",
          "fields":[
            {
              "id":"budget_approved",
              "title":"Budget Approved",
              "type":"switch",
              "styles":{
                "tint_color":"#CBEDBF"
              },
              "value":false,
              "size":{
                "width":50,
                "height":1
              }
            }
          ]
        }
      ]
    }
  ]
}

Accessibility Labels

Accessibility labels are used by VoiceOver on iOS to provide feedback to users with visual impairments. According to Apple, the accessibility label attribute is "a short, localized word or phrase that succinctly describes the control or view, but does not identify the element's type. Examples are 'Add' or 'Play.'"

Field values are automatically mapped to Accessibility Value attributes to provide accurate feedback to users.

In addition to providing assistive feedback to users with impairments, accessibility labels can be useful for UI testing. Libraries such as KIF, EarlGrey, and Calabash can use accessibility labels to access and control fields.

Example JSON

{
  "groups":[
    {
      "id":"group1",
      "title":"Accessibility Example",
      "sections":[
        {
          "id":"section1",
          "fields":[
            {
              "id":"first_name",
              "title":"First Name",
              "info":"Enter your first name",
              "accessibility_label":"First Name Accessibility Label",
              "type":"name",
              "size":{
                "width":25,
                "height":1
              }
            }
          ]
        }
      ]
    }
  ]
}

FAQ

How do I get the contents of a field?

FORMField *targetField = [dataSource fieldWithID:@"display_name" includingHiddenFields:YES];
id value = targetField.value;
// Do something with value

How do I get all the values of the Form?

NSDictionary *initialValues = @{@"email" : @"[email protected]",
                                @"companies[0].name" : @"Facebook",
                                @"companies[0].phone_number" : @"1222333"};

FORMDataSource *dataSource = [[FORMDataSource alloc] initWithJSON:JSON
                                                   collectionView:nil
                                                           layout:nil
                                                           values:initialValues
                                                         disabled:NO];
NSDictionary *values = dataSource.values;
// Do something with values

How do I make a universal Form?

You have to specify and iPhone specific JSON file. Something like this, check the iPhone-Storyboard demo for more information.

We went for this approach since it gives the developers more control over the UI. You have to add a check for device and present the JSON file that matches the device.

How do I dynamically update a field's values?

The method below takes two arguments: fieldID and options. The fieldID argument is simply an NSString with the ID of the field to update. The options argument is an NSArray of NSDictionaries with valueID, valueName, and defaultValue keys. A similar approach could be used to take data from another method or web-service and update your field with it. This approach can be used with select and segment fields.

- (void)updateSelectField:(NSString *)fieldID withOptions:(NSArray *)options {
    __weak typeof(self)weakSelf = self;

    [self.dataSource fieldWithID:fieldID includingHiddenFields:YES completion:^(FORMField *field, NSIndexPath *indexPath) {
        NSMutableArray *values = @[].mutableCopy;

        for (NSDictionary *option in options) {
            FORMFieldValue *fieldValue = [FORMFieldValue new];
            fieldValue.valueID = [option valueForKey:@"valueID"];
            fieldValue.title = [option valueForKey:@"valueName"];
            fieldValue.default = [option valueForKey:@"defaultValue"];
            fieldValue.field = field;

            [values addObject:fieldValue];
        }

        field.values = [values copy];

        if (!field.hidden) {
          [weakSelf.dataSource reloadFieldsAtIndexPaths:@[indexPath]];
        }
    }];
}

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.

Detailed discussions regarding code might be easier to have in the Form channel on Gitter.

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.

You might also like...
Carbon🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.
Carbon🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.

A declarative library for building component-based user interfaces in UITableView and UICollectionView. Declarative Component-Based Non-Destructive Pr

SwiftForms is a small and lightweight library written in Swift that allows you to easily create forms.
SwiftForms is a small and lightweight library written in Swift that allows you to easily create forms.

SwiftForms is a powerful and extremely flexible library written in Swift that allows to create forms by just defining them in a couple of lines. It also provides the ability to customize cells appearance, use custom cells and define your own selector controllers.

Discover new programming concepts and more new SwiftUI 2 features in this section

Africa-Zoo One thing is sure, we will discover new programming concepts and more new SwiftUI 2 features in this section. TOPICS ARE COVERED: JSON with

 SwiftyFORM is a lightweight iOS framework for creating forms
SwiftyFORM is a lightweight iOS framework for creating forms

SwiftyFORM is a lightweight iOS framework for creating forms Because form code is hard to write, hard to read, hard to reason about. Has a

Boring-example - Using boring crate from iOS application

BoringSSL example Using boring crate from iOS application. Checkout git clone gi

iOS Validation Library

Honour Validation library for iOS inspired by Respect/Validation. Validator.mustBe(Uppercase()).andMust(StartsWith("F")).validate("FOOBAR") ❗ If you w

GrouponHeader - iOS TableView Header Animation, Swift/UIKit
GrouponHeader - iOS TableView Header Animation, Swift/UIKit

GrouponHeader Description: iOS TableView Header Animation Technology: Swift, UIK

Meet CRRulerControl - Customizable Control for iOS
Meet CRRulerControl - Customizable Control for iOS

Customizable component, created by Cleveroad iOS developers, is aimed at turning a simple ruler into a handy and smart instrument

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.
XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.

XLForm By XMARTLABS. If you are working in Swift then you should have a look at Eureka, a complete re-design of XLForm in Swift and with more features

ObjectForm - a simple yet powerful library to build form for your class models.
ObjectForm - a simple yet powerful library to build form for your class models.

ObjectForm A simple yet powerful library to build form for your class models. Motivations I found most form libraries for swift are too complicated to

The most powerful Grid container missed in SwiftUI
The most powerful Grid container missed in SwiftUI

Grid Grid view inspired by CSS Grid and written with SwiftUI We are a development agency building phenomenal apps. Overview Grid is a powerful and eas

The most powerful Event-Driven Observer Pattern solution the Swift language has ever seen!
The most powerful Event-Driven Observer Pattern solution the Swift language has ever seen!

Event-Driven Swift Decoupling of discrete units of code contributes massively to the long-term maintainability of your project(s). While Observer Patt

Swift-multipart-formdata - MultipartFormData: Build multipart/form-data type-safe in Swift

MultipartFormData Build multipart/form-data type-safe in Swift. A result builder

AwaitKit is a powerful Swift library which provides a powerful way to write asynchronous code in a sequential manner.
AwaitKit is a powerful Swift library which provides a powerful way to write asynchronous code in a sequential manner.

AwaitKit is a powerful Swift library inspired by the Async/Await specification in ES8 (ECMAScript 2017) which provides a powerful way to write asynchronous code in a sequential manner.

A declarative, thread safe, and reentrant way to define code that should only execute at most once over the lifetime of an object.

SwiftRunOnce SwiftRunOnce allows a developer to mark a block of logic as "one-time" code – code that will execute at most once over the lifetime of an

A fast & simple, yet powerful & flexible logging framework for Mac and iOS
A fast & simple, yet powerful & flexible logging framework for Mac and iOS

CocoaLumberjack CocoaLumberjack is a fast & simple, yet powerful & flexible logging framework for macOS, iOS, tvOS and watchOS. How to get started Fir

The most swifty way to deal with XML data in swift 5.

SwiftyXML SwiftyXML use most swifty way to deal with XML data. Features Infinity subscript dynamicMemberLookup Support (use $ started string to subscr

A powerful SwiftUI Architecture that merges Redux to the functional world of Swift. While bringing powerful workflows to streamline CoreML/Metal/IPFS usage in the Apple ecosystem.
A powerful SwiftUI Architecture that merges Redux to the functional world of Swift. While bringing powerful workflows to streamline CoreML/Metal/IPFS usage in the Apple ecosystem.

GraniteUI - v0.0 - WIP A powerful SwiftUI Architecture that merges Redux event handling and state management with functional programming. While bringi

A simple and flexible way to add source of overlapping circular pictures, currently supports horizontal overlapping or distant pictures with great layout flexibility.
A simple and flexible way to add source of overlapping circular pictures, currently supports horizontal overlapping or distant pictures with great layout flexibility.

THIS PROJECT IS NO LONGER MAINTAINED. STILL ONE ONLY BEST UI SOLUTION FOR UIKIT DEVELOPERS. SOON WILL COME UP WITH SWIFTUI STILL CONTRIBUTORS ARE WELC

Owner
HyperRedink
Connected creativity
HyperRedink
ObjectForm - a simple yet powerful library to build form for your class models.

ObjectForm A simple yet powerful library to build form for your class models. Motivations I found most form libraries for swift are too complicated to

jakehao 175 Nov 2, 2022
SherlockForms - An elegant SwiftUI Form builder to create a searchable Settings and DebugMenu screens for iOS

??️‍♂️ SherlockForms What one man can invent Settings UI, another can discover i

Yasuhiro Inami 98 Dec 27, 2022
Elegant iOS form builder in Swift

Made with ❤️ by XMARTLABS. This is the re-creation of XLForm in Swift. 简体中文 Overview Contents Requirements Usage How to create a Form Getting row valu

xmartlabs 11.6k Jan 1, 2023
Declarative form building framework for iOS

Formalist Swift framework for building forms on iOS Formalist is a Swift framework for building forms on iOS using a simple, declarative, and readable

Seed 159 May 25, 2022
iOS validation framework with form validation support

ATGValidator ATGValidator is a validation framework written to address most common issues faced while verifying user input data. You can use it to val

null 51 Oct 19, 2022
APValidators - Codeless solution for form validation in iOS!

APValidators is a codeless solution for form validation. Just connect everything right in Interface Builder and you're done. Supports really complex and extendable forms by allowing to connect validators in tree.

Alty 131 Aug 16, 2022
Former is a fully customizable Swift library for easy creating UITableView based form.

Former is a fully customizable Swift library for easy creating UITableView based form. Submitting Issues Click HERE to get started with filing a bug r

Ryo Aoyama 1.3k Dec 27, 2022
Some cells to Form a Pod

CellsGao Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation CellsGao

null 0 Nov 2, 2021
Custom Field component with validation for creating easier form-like UI from interface builder.

#YALField Custom Field component with validation for creating easier form-like UI from interface builder. ##Example Project To run the example project

Yalantis 476 Sep 1, 2022
A framework to validate inputs of text fields and text views in a convenient way.

FormValidatorSwift The FormValidatorSwift framework allows you to validate inputs of text fields and text views in a convenient way. It has been devel

ustwo™ 500 Nov 29, 2022