JSON驱动的iOS表单:Form

jopen 10年前

最灵活和强大的方式来在iOS上构建一个表单。

Form源于有一个需求,需要一个表单在iOS app和网页客户端之间能共享逻辑,发现JSON是完成这项目的最佳方式。

Form包含了以下特性:

  • 多个分组: For example you can have a group for personal details and another one for shipping information
  • 表单验证: We supportrequired,maximum length,minimum lengthandformat(regex). We also support many field types, for example:text,number,phone_number,email,date,nameand more
  • 自定义大小: Totalwidthis handled as 100% whileheightis handled in chunks of 85 px
  • 自定义表单项: You can register your custom fields, it's pretty simple (our basic example includes how to make animagefield)
  • 公式或计算的值: We support fields that contain generated values from other fields
  • Targets:Hide,show,update,enable,disableorcleara 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 supportdefaultflags, 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)

用法

基本Form

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

JSON驱动的iOS表单: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 subclass  - (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;  }

项目主页:http://www.open-open.com/lib/view/home/1425972167654