Git Product home page Git Product logo

vlrtextfield's Introduction

VLRTextField

VeryLastRoom iOS textField

alt tag alt tag

Purpose

This class intention is to provide an extension to the power of two great libraries on UITextField:

  • JVFloatLabeledTextField which purpose is to nicely display the place holder on top on the textfield when inserting text
  • HTAutocompleteTextField which purpose is to provide autocompletion (for example: emails, company names, ...)

VLRTextfield adds a new layer: validation (for example, it is great on forms). You can then specify several check behaviors like:

  • check content with regex (@see regex) AND/OR
  • fill optional or not (@see fillRequired) AND/OR
  • minimum number of characters to enter (for example: 8 characters for password) (@see minimumNumberOfCharacters) AND/OR
  • custom validation block (@see validateBlock).

All of these tests can be run on demand or while editing. #Examples

Classic text field

VLRTextField *name          = [VLRTextField myAppCustomizedTextFieldWithPlaceholder:@"Enter your first name"];
name.autocapitalizationType = UITextAutocapitalizationTypeWords;
name.formKeyPath            = @"name";
name.messageRequired        = @"Your first name is required";

Regex text field

static NSString *REGULAR_EXPRESSION_EMAIL = @"[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@([a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,6}";

VLRTextField *email          = [VLRTextField myAppCustomizedTextFieldWithPlaceholder:@"Enter an email to reach you"];
email.keyboardType           = UIKeyboardTypeEmailAddress;
email.regex                  = REGULAR_EXPRESSION_EMAIL;
email.messageInvalid         = @"Your email address is invalid";
email.messageRequired        = @"Please enter an email adress";
email.formKeyPath            = @"email_address";
email.autocompleteDataSource = [VLRAutoCompleteManager sharedManager];
email.autocompleteType       = VLRAutocompleteTypeEmail;

Notice VLRAutoCompleteManager. See HTAutocompleteTextField.

Minimum characters text field

VLRTextField *password             = [VLRTextField myAppCustomizedTextFieldWithPlaceholder:@"Enter a password"];
password.minimumNumberOfCharacters = 8;
password.messageRequired           = @"The password should be 8 characters long";
password.formKeyPath               = @"password_1";
password.secureTextEntry           = YES;

Custom validation block text field

We use the block to check if the two passwords are the same:

VLRTextField *passwordConfirmation             = [VLRTextField formTextFieldWithFrame:CGRectMake(kXOffset, kYOffset + CGRectGetMaxY(password.frame), width, kTextFieldHeight) placeholder:@"Re enter your password"];
passwordConfirmation.messageInvalid            = @"The two passwords should match";
passwordConfirmation.messageRequired           = @"Please re enter your password";
passwordConfirmation.minimumNumberOfCharacters = password.minimumNumberOfCharacters;
passwordConfirmation.formKeyPath               = @"password_2";
passwordConfirmation.secureTextEntry           = YES;
passwordConfirmation.validateBlock             = ^BOOL(VLRTextField *textField) {
    return [[password text] isEqualToString:textField.text];
};

Not required text field

VLRTextField *company          = [VLRTextField formTextFieldWithFrame:CGRectMake(kXOffset, kYOffset + CGRectGetMaxY(passwordConfirmation.frame), width, kTextFieldHeight) placeholder:@"Enter the company you work for"];
company.fillRequired           = NO;
company.formKeyPath            = @"company_name";
company.autocompleteDataSource = [VLRAutoCompleteManager sharedManager];
company.autocompleteType       = VLRAutoCompleteCompany;
company.autocapitalizationType = UITextAutocapitalizationTypeSentences;
company.returnKeyType          = UIReturnKeyDone;

Notice VLRAutoCompleteManager. See HTAutocompleteTextField.

##The one more thing

Along with validating the content the user enters, you can also use VLRFormService to:

  • handle automatic next if returnKeyType is equal to UIReturnKeyNext
  • check form and show errors (or not)
  • extract a JSON as NSDictionary from registered textFields.

Do not hesitate to subclass VLRFormService to add new behaviors fitting your need.

How to use VLRFormService

self.registerTextFieldManager          = [VLRFormService new];

// The order does matter (for next behavior)
[self.registerTextFieldManager addTextField:name];
[self.registerTextFieldManager addTextField:email];
[self.registerTextFieldManager addTextField:password];
[self.registerTextFieldManager addTextField:passwordConfirmation];
[self.registerTextFieldManager addTextField:company];

Check form

Check and display errors:

- (void) send {
    BOOL formValid = [self.registerTextFieldManager checkForm]; // Will check and display errors
    if (formValid) {
        [self.registerTextFieldManager.activeField resignFirstResponder];
        [self safelySend];
    }
}

Check without displaying errors

BOOL formValid = [self.registerTextFieldManager checkFormAndShowErrors:NO];

Extract JSON

This will use formKeyPath property on VLRTextField

NSDictionary *json = [self.registerTextFieldManager extractFieldsAsJson];

vlrtextfield's People

Contributors

ekhoo avatar ipodishima avatar shouze avatar

Stargazers

 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

vlrtextfield's Issues

Allow modification of the 'backgroundColor' property of errorMessageView

I'm able to customize every property for a text field and related views except for this one. In order to get the behaviour I wanted I had to modify this property within the framework itself, because the 'errorMessageView' label gets created in 'addErrorViewFromError' and thus remains within that scope.

If I missed something obvious, my apologies - maybe you could point me in the right direction? :) This is a fantastic library otherwise

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.