Giter VIP home page Giter VIP logo

bzgformviewcontroller's Introduction

BZGFormViewController Build Status

BZGFormViewController is a simple library for making dynamic forms.

alt tag

Demo app

Navigate to SignupForm, run pod install, and open SignupForm.xcworkspace. Build and run to see BZGFormViewController in action.

Installation

Cocoapods is the recommended method of installing BZGFormViewController. Add the following line to your Podfile:

pod `BZGFormViewController`

Quick start

First, subclass BZGFormViewController.

@interface SignupViewController : BZGFormViewController

Next, import "BZGTextFieldCell.h" and create a cell.

#import "BZGTextFieldCell.h"

// ...

self.usernameCell = [BZGTextFieldCell new];
self.usernameCell.label.text = @"Username";

To validate text and update the cell when the cell's text changes, use the cell's shouldChangeTextBlock.

self.usernameCell.shouldChangeTextBlock = ^BOOL(BZGTextFieldCell *cell, NSString *newText) {
    if (newText.length < 5) {
        cell.validationState = BZGValidationStateInvalid;
    } else {
        cell.validationState = BZGValidationStateValid;
    }
    return YES;
};

Each BZGTextFieldCell contains a BZGInfoCell. The info cell will be displayed if the cell's validationState is either BZGValidationStateInvalid or BZGValidationStateWarning. You can set the info cell's text using setText:.

self.usernameCell.shouldChangeTextBlock = ^BOOL(BZGTextFieldCell *cell, NSString *newText) {
    if (newText.length < 5) {
        cell.validationState = BZGValidationStateInvalid;
        [cell.infoCell setText:@"Username must be at least 5 characters long."];
    } else {
        cell.validationState = BZGValidationStateValid;
    }
    return YES;
};

BZGFormViewController automatically scrolls the tableview when you begin editing a text field and moves to the next field when you hit return.

You should use BZGTextFieldCell's shouldChangeTextBlock, didBeginEditingBlock, didEndEditingBlock, and shouldReturnBlock for validation and any other logic you would usually put in UITextFieldDelegate methods.

After you've configured your cells, add them into the desired section

[self addFormCells:@[self.usernameCell, self.emailCell, self.passwordCell] 
         atSection:0];
[self addFormCells:@[self.phoneCell] atSection:1];

Custom sections

BZGFormViewController will only manage sections containing form cells. If you'd like to have other sections containing custom cells, you'll have to manage them yourself via the UITableViewDataSource methods. Be sure to use the values from super for the table view's form section.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section > 1) {
        return [super tableView:tableView numberOfRowsInSection:section];
    } else {
        return 1;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section > 1) {
        return [super tableView:tableView cellForRowAtIndexPath:indexPath];
    } else {
        return self.otherCell;
    }
}

Contributing

Please write tests and make sure existing tests pass. Tests can be run from the demo project in /SignupForm. See the Roadmap for planned improvements.

bzgformviewcontroller's People

Contributors

ayanonagon avatar marklarr avatar miwillhite avatar vizh avatar vprtwn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bzgformviewcontroller's Issues

Add phone text field cell

Should autoformat input with ()-, maybe add a text property that returns the numeric phone number?

Auto-update to latest Minor+Patch versions of Reactive Cocoa

In order to avoid

[!] Unable to satisfy the following requirements:
- `ReactiveCocoa (~> 2.2.4)` required by `BZGFormViewController (2.4.3)`
- `ReactiveCocoa (~> 2.3)` required by `Podfile`

when a project updates to a newer version of the Reactive Cocoa pod

Consider pulling in a validation framework like US2FormValidator?

I'm really liking this form controller you've built. I haven't ever worked with ReactiveCocoa before so it's a little unusual, but I think it could revolutionize the logic in view controllers.

I was curious if you've ever looked into integrating a beefier validation framework? I'll likely try to wire this into the US2FormValidator library since that's what we use internally already.

BZGFormViewController arm64 compatibility

This controller crash at compile in iPad Air but no in iPad Simulator. The external libraries crash with errors:

libffi/ios/include/ffi_common.h:77:1: Unknown type name 'ffi_status'

any solution?

Add showsValidationWhileEditing to BZGFormFieldCell

showsValidationStateWhileEditing should default to NO.
if YES, the field should display its validation state while the user is editing the textfield, i.e.

  • red text when the field is invalid
  • checkmark when the field is valid

A nice to have:
The infoCell should appear while the user is editing the field if shouldShowInfoCell is true and the user pauses for >1 sec. The info cell should disappear if the user starts typing again.

How to disable login or sign up cell

I am able to change the state of login/ sign up cell to invalid. But how do I make it so that in function tableView:didSelectRowAtIndexPath I do not call the backend method if both are empty ?

How do I check the state of the cell there ?

It gives me '-[UITableViewCell validationState:]: unrecognized selector sent to instance 0x15cd2ad30'

Problem with libPhoneNumber-iOS

I have this issue when I ran a "pod install" with both pod 'BZGFormViewController' 'BZGMailgunEmailValidation' inside.
Now, each time I try to build the application, compiler give me this error.
suggestions?
thanks a lot,
Dario
schermata 2016-01-12 alle 15 43 10

Always-valid field with disabled checkmark does not work

I have an optional field in my form (surname prefix 'von Damme' -> 'von' and 'Damme', very common in the Netherlands). I don't want to show a checkmark when no input is given, but the validation state must always be Valid so that an empty field is also accepted.

Sounds easy enough:

_prefixCell.validationState = BZGValidationStateValid;
_prefixCell.showsCheckmarkWhenValid = NO;

I do not use any validation block. It is however rendered incorrectly: it is indeed valid, but even before typing anything, it shows the checkmark.

Could you look into this?

`initWithCoder` not handled

Hi, and thanks for that component !

Btw, the initWithCoder method of BZGFormViewController isn't implemented.
That creates an infinite loop when its initializer is called.

As you can implement it or simply move style and formCellsBySection properties in the header file (and let developer initialize these values), I let you do the change :)

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.