aokudan / Form

JSON driven form

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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, maximum_length, minimum_length and format (regex). We also support many field types, for example: 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, 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, 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 values or numeric values and subtitles (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.

At the moment Form only supports the iPad, support for the iPhone will come soon.

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];

    //...
}
UICollectionViewController
- (FORMDataSource *)dataSource
{
    if (_dataSource) return _dataSource;

    _dataSource = [[FORMDataSource alloc] initWithJSON:self.JSON
                                        collectionView:self.collectionView
                                                layout:self.layout
                                                values:nil
                                              disabled:NO];

    return _dataSource;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.collectionView.dataSource = self.dataSource;
}

Targets

Targets are one of the most powerful features of form, we support: 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
            }
          }
        ]
      }
    ]
  }
]

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 if you're using this library we probably want to hire you.

License

Forms is available under the MIT license. See the LICENSE file for more info.

About

JSON driven form

License:Other


Languages

Language:Objective-C 99.4%Language:Ruby 0.5%Language:Perl 0.2%