Forms

Native forms make it easier than ever to add rich forms to your applications. Every iOS developer knows the headaches that are associated with creating forms on iOS, especially forms with different types of input views and validation. With Managed Forms the logistics are done by Redbeard, allowing you to concentrate on what’s important.

Schemas

Native Forms allow you to express the form you want in clear terms using a schema. The logistics are then handled by Redbeard - just wait for the delegate callback to deliver the validated results to you!

You can control the way the form looks to a great extent by providing theming information for items and by specifying your own positioner if necessary. Additionally, schemas can be serialised and deserialised using JSON, making it easy to drive your forms from the server-side if you so wish!

Here’s an example schema and the corresponding form that it produces:

                    RBManagedFormTextFieldSchema *usernameField = [RBManagedFormTextFieldSchema new];
usernameField.fieldName = @"username";
usernameField.placeholder = @"Username";
usernameField.title = @"Username";
   
RBManagedFormTextFieldSchema *passwordField = [RBManagedFormTextFieldSchema new];
passwordField.fieldName = @"password";
passwordField.placeholder = @"Password";
passwordField.secureTextEntry = true;
passwordField.title = @"Password";
   
RBManagedFormListFieldSchema *genderField = [RBManagedFormListFieldSchema new];
genderField.fieldName = @"gender";
genderField.type = RBManagedFormListFieldTypeInline;
genderField.listItems = @[ @"Male", @"Female" ];
genderField.title = @"Gender";
   
RBManagedFormPhotoFieldSchema *profilePicField = [RBManagedFormPhotoFieldSchema new];
profilePicField.fieldName = @"profilePicture";
profilePicField.title = @"Profile Pic.";
   
RBManagedFormSubmitButtonSchema *submitButton = [RBManagedFormSubmitButtonSchema new];
   
RBManagedFormSchema *schema = [RBManagedFormSchema schemaWithItems:@[ usernameField, passwordField, genderField, profilePicField, submitButton ]];
   
[self.formView setFormSchema:schema];
                    

Managed

Redbeard will manage the form for you, taking care of the following so you don’t have to think about it:

  • Managing and positioning the form fields.
  • Managing the keyboard and responding correctly to events.
  • Validating the form fields and providing natural user feedback.
The results of a form are provided as an 'NSDictionary' object. Here’s an example of such a dictionary for the form example above:
                    {
    gender = Male;
    password = password;
    profilePicture = "<uiimage: 0x7a90d820> size {2048, 2048} orientation 0 scale 1.000000";
    username = Steve;
}
                        

Fields

The standard iOS form fields are provided, including:

  • Text Field
  • Text View (Multiline)
  • Switch
  • List Picker
  • Date/Time Picker

In addition, the following fields are provided by Redbeard:

Photo Field - Allows the user to take a photo with the camera, or choose one from the device.

Photo-Field

Image Selection Field - Provides a selection of images from which the user can select one or more.

Image selection field

Inline List Selection Fields (inc. Multiselect) - Provides a list of items inline from which the user can select one or more.

Inline list field

Numeric Range Field (Slider) - Provides sliders with which the user can select a numeric range, such as a price range with a given minimum and maximum.

Numeric range field
We’ve also made it possible for you to write your own form control and corresponding schema, such that it’s completely compatible with managed forms.

Validation

All form fields can be validated. Add any number of validation rules to a field with the corresponding messages. Redbeard will then ensure that these are met and when they aren’t, the user will be clearly informed using tooltips and taken to the field to correct it. You’ll only be disturbed when the form is valid!

Form fields also have a theme-able states for valid and invalid validation results, allowing you to control how a field looks when validation fails or succeeds (for example giving a red or green border).

There are many expressive validation rules, including the following, with a custom rule allowing you to write your own code in the situation where what we have provided isn’t sufficient for your needs!

  • Field cannot be empty.
  • Enforce a range, minimum or maximum for:
    • Numeric Input
    • Photo Image Size
    • String Length
    • Item Count (Array Size)
  • The aspect ratio of a photo image.

Using the previous form schema example, we can add some validation rules like so:

                id usernameNotEmptyRule = [RBManagedFormValidationRuleSchema nonEmptyRuleWithFailureMessage:@"You must choose a username!"];
usernameField.validationRules = @[ usernameNotEmptyRule ];
   
id passwordNotEmptyRule = [RBManagedFormValidationRuleSchema nonEmptyRuleWithFailureMessage:@"You must choose a password!"];
id passwordLengthRule = [RBManagedFormValidationRuleSchema ruleWithStringLengthMinimumLength:8 failureMessage:@"The password cannot be less than 8 characters in length."];
passwordField.validationRules = @[ passwordNotEmptyRule, passwordLengthRule ];

id genderNotEmptyRule = [RBManagedFormValidationRuleSchema nonEmptyRuleWithFailureMessage:@"You must choose a gender!"];
genderField.validationRules = @[ genderNotEmptyRule ];
                

Inline Popup Form

When you have your form schema, you can assign it to a managed form view, or you can open it as a pop-up inline. On any UIViewController, you can simply make a single method call providing the form schema and providing a block to handle the result. The form will then animate into view, looking very professional and with minimal effort. You can even finely control the details of the presentation transition - or write your own - if you so wish!

                    RBManagedFormAlertSchema *schema = [RBManagedFormAlertSchema new];
schema.formSchema = ...;
   
[self formAlertWithSchema:schema buttonSelected:nil animated:true completion:^(NSDictionary *results, BOOL wasCancelled) {
// Do something here! 
}];

Responsive and Theme-able

Form is completely theme-able, including layout and all fields.


Form is responsive and adjusts to changing environments.

Sample

Click here to follow the form sample to learn more and use forms for yourself!