Skip to content

nagyist/MBFormCoordinator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

##MBFormCoordinator

Easily chain, bind, and validate text fields.

Every app I've ever created has always had a form of some sort. And in every app, I've found myself always recreating the same basic components:

  • chaining fields so that a user can advance from one to the other
  • validating values of fields
  • associating the text of a field to a model property.

This library does this for you, so you don't have to reinvent the wheel everytime.

##Features ####Chain text fields:

MBFormCoordinator *form = [MBFormCoordinator newWithDelegate:self];
[form chainFields:@[_firstNameField, _emailField, _confirmEmailField] finishType:UIReturnKeyJoin];

####Bind field values to a model

[form bindKeyPath:@"firstName" ofObject:_user toField:_firstNameField];
[form bindKeyPath:@"email" ofObject:_user toField:_emailField];

####Validate fields MBFormCoordinator handles field validation. Just implement the following delegate methods:

- (MBFieldValidationType)validationTypeForField:(id)field atIndex:(NSUInteger)index
{
    switch (index) {
        case 0: return MBFieldValidationTypeName;
        case 1: return MBFieldValidationTypeEmail;
        case 2: return MBFieldValidationTypeEmailConfirmation;
        default: return MBFieldValidationTypeNone;
    }
}

- (MBValidationError*)validationErrorForField:(id)field validatonType:(MBFieldValidationType)type atIndex:(NSUInteger)index
{
	  return [MBValidationError errorWithName:@"Invalid value" details:@"You've entered an invalid value for one of the fields"];
}

- (void)validationDidFailForField:(id)field atIndex:(NSUInteger)index withError:(MBValidationError *)error
{
    [[[UIAlertView alloc] initWithTitle:error.name message:error.details
     delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil] show];
}

- (void)formDidComplete:(MBFormCoordinator *)form
{
	// handle form completion
}

##Important MBFormCoordinator must be the delegate to all fields, so make sure you don't set the delegate property for your UITextField or UITextView. The form coordinator will however forward all UITextField and UITextView delegate callbacks to the form delegate.

About

Easily chain, bind, and validate text fields.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published