TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Nov 2015 |
Maintained by Marian Paul, Sébastien HOUZÉ, Lucas Ortis.
Depends on: | |
PPHelpMe | ~> 1.0.2 |
VLRJVFloatLabeledTextField | ~> 1.0.3 |
VeryLastRoom iOS textField
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 textHTAutocompleteTextField
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:
regex
) AND/ORfillRequired
) AND/ORminimumNumberOfCharacters
) AND/ORvalidateBlock
).All of these tests can be run on demand or while editing.
VLRTextField *name = [VLRTextField myAppCustomizedTextFieldWithPlaceholder:@"Enter your first name"];
name.autocapitalizationType = UITextAutocapitalizationTypeWords;
name.formKeyPath = @"name";
name.messageRequired = @"Your first name is required";
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
.
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;
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];
};
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
.
Along with validating the content the user enters, you can also use VLRFormService
to:
returnKeyType
is equal to UIReturnKeyNext
NSDictionary
from registered textFields.Do not hesitate to subclass VLRFormService
to add new behaviors fitting your need.
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 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];
This will use formKeyPath
property on VLRTextField
NSDictionary *json = [self.registerTextFieldManager extractFieldsAsJson];