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.
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];
Redbeard will manage the form for you, taking care of the following so you don’t have to think about it:
{
gender = Male;
password = password;
profilePicture = "<uiimage: 0x7a90d820> size {2048, 2048} orientation 0 scale 1.000000";
username = Steve;
}
The standard iOS form fields are provided, including:
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.
Image Selection Field - Provides a selection of images from which the user can select one or more.
Inline List Selection Fields (inc. Multiselect) - Provides a list of items inline from which the user can select one or more.
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.
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!
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 ];
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!
}];
Form is completely theme-able, including layout and all fields.
Form is responsive and adjusts to changing environments.
Click here to follow the form sample to learn more and use forms for yourself!
We'll regularly be releasing awesome samples and end to end Apps with full source code. If you'd like to be the first to know then please leave your email below and we'll be in touch as soon as there's something new: