Code Monkey home page Code Monkey logo

mbformcoordinator's Introduction

##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.

mbformcoordinator's People

Contributors

moughxyz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.