Simple interactive and customizable library to handle form input and validations.

Related tags

Form LightForm
Overview

LightForm

CI Status Version License Platform

LightForm

Simple interactive and customizable library to handle form input and validations.

demo

A simple library which let the user create beautiful and interactive forms for handling user inputs and validating the data as the user inputs. The library notifies the caller if and when the user changes the input and let the caller decide what is validated and what validation messages needs to be displayed.

While developing Log In and Sign Up pages I ran into many use cases where the rules for username or password and it is common to provide feedback to the user as they type in value. This library uses blocks to notify the user of any input changes and then let the user update the validation string if needed.

Features

  • customize the font and color used for displaying the placeholder
  • customize the font and color used for displaying the input text
  • customize the image displayed on each cell
  • the keyboard can display "Next" or "Go" based on the cell data.

While developing Log In and Sign Up pages I ran into many use cases where the rules for username or password and it is common to provide feedback to the user as they type in value.

In the demo the caller validates the input username and password and as the user types it can provide feedback. Since validation label is refreshed upon each user input the user can see immediate feedback.

Usage

pod install

    pod install

import the library

#import "LightForm.h"

Register LightFormCell with an identifier. You can also use "Interface Builder" if you are designing the view controller using the storyboards.

[self.tableView registerClass:[LightFormCell class] forCellReuseIdentifier:@"SignUpFormCellId"];

Create form data. In this example we will create You can create the form data using "Dictionary" or by creating an instance of LightFormCellData.

- (void)tableView:(UITableView *)tableView
  willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
    LightFormCell *lightFormCell = (LightFormCell *) cell;
    lightFormCell.data = [LightFormCellData fromDictionary:
    @{@"key": @"username",
       @"placeholder": @"Username",
       @"hasNext": @(YES)}];
}

In order to validate the user input as it is being typed you can handle.

[cell executeBlock:^(LightFormCellData *data, BOOL focused, NSString *input, BOOL returned, BOOL goToNext) {
       BOOL updatedNeeded = NO;
      
       if (input) {
           // format the validation message as red
           data.validations = @[[[NSAttributedString alloc] 
           initWithString:@"x at least 8 characters" attributes:@{NSForegroundColorAttributeName: [UIColor redColor]}]];
           // or if you dont need to format the validation message
           data.validations = @[@"x at least 8 characters"];
       }
];

implement this method in order to specify the height for this cell

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {

        return [LightFormCell cellHeightForData:form[(NSUInteger) indexPath.row]
                                      withStyle:[[LightFormDefaultStyle alloc] init]];

}

in order to transfer the control to the next cell ( e.g when user selects next button the caller can decide which control should become the first responder next)

[cell executeBlock:^(LightFormCellData *data, BOOL focused, NSString *input, BOOL returned, BOOL goToNext) {
       if (goToNext) {
           UIResponder *nextResponder = [self.view viewWithTag:cell.tag + 1];
           [nextResponder becomeFirstResponder];
       }
}];

hide the input validation if the cell is not selected anymore

[cell executeBlock:^(LightFormCellData *data, BOOL focused, NSString *input, BOOL returned, BOOL goToNext) {
        if (returned) {
            data.validations = nil;
        }
];

list of properties that can be customized

@protocol LightFormStyle <NSObject>

@optional

/**
 * the cell border color
 */
@property(nonatomic, retain) UIColor *borderColor;

/*
 * the cell border color when it is selected
 */
@property(nonatomic, retain) UIColor *selectedBorderColor;

/*
 * the cell border width when it is not selected
 */
@property(nonatomic) NSUInteger borderWidth;

/*
 * the cell border width when it is selected
 */
@property(nonatomic) NSUInteger selectedBorderWidth;

/*
 * the border opacity when cell is not selected
 */
@property(nonatomic) float borderOpacity;

/*
 * the border opacity when cell is selected
 */
@property(nonatomic) float selectedBorderOpacity;

/*
 * the color used for displaying the validation messages
 */
@property(nonatomic, retain) UIColor *validationColor;

/*
 * the font used for displaying the validation messages
 */

@property(nonatomic, retain) UIFont *validationFont;

/*
 * the font used for formatting the text input by the user
 */
@property(nonatomic, retain) UIFont *titleFont;

/*
 * the text color for formatting the text input by the user
 */

@property(nonatomic, retain) UIColor *titleColor;

/*
 * the font used while displaying the placeholder text
 */
@property(nonatomic, retain) UIFont *placeholderFont;

/*
 * the text color used when displaying the placeholder text
 */
@property(nonatomic, retain) UIColor *placeholderColor;

/*
 * the image displayed on the right side of the cell
 */
@property(nonatomic, retain) UIImage *accessoryImage;

/*
 * they keyboardtype displayed when editing this cell
 */
@property(nonatomic) UIKeyboardType keyboardType;
/*
 * the autocorrectiontype used when keyboard is active
 */
@property(nonatomic) UITextAutocorrectionType autocorrectionType;

/*
 * the return key type used while this cell is being used. by default this
 * is set to "Next" or "Go" based on the CellData.hasNext property
 */
@property(nonatomic) UIReturnKeyType returnKeyType;

/*
 * the cell contentInset
 */
@property(nonatomic) UIEdgeInsets contentInsets;

@end

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

LightForm is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "LightForm"

Todo

1- add ability to show or hide the password 2- add ability to modify the placeholder or text font and color without having to refresh the cell 3- add a protocol that can be used to handle the input validation

Author

Farshid Ghods, [email protected]

License

LightForm is available under the MIT license. See the LICENSE file for more info.

You might also like...
Meet CRRulerControl - Customizable Control for iOS
Meet CRRulerControl - Customizable Control for iOS

Customizable component, created by Cleveroad iOS developers, is aimed at turning a simple ruler into a handy and smart instrument

Carbon🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.
Carbon🚴 A declarative library for building component-based user interfaces in UITableView and UICollectionView.

A declarative library for building component-based user interfaces in UITableView and UICollectionView. Declarative Component-Based Non-Destructive Pr

SwiftForms is a small and lightweight library written in Swift that allows you to easily create forms.
SwiftForms is a small and lightweight library written in Swift that allows you to easily create forms.

SwiftForms is a powerful and extremely flexible library written in Swift that allows to create forms by just defining them in a couple of lines. It also provides the ability to customize cells appearance, use custom cells and define your own selector controllers.

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.
XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. Fully compatible with Swift & Obj-C.

XLForm By XMARTLABS. If you are working in Swift then you should have a look at Eureka, a complete re-design of XLForm in Swift and with more features

Simple ui check box

CheckBox Example To run the example project, clone the repo, and run pod install from the Example directory first.

A rule-based validation library for Swift
A rule-based validation library for Swift

SwiftValidator Swift Validator is a rule-based validation library for Swift. Core Concepts UITextField + [Rule] + (and optional error UILabel) go into

iOS Validation Library

Honour Validation library for iOS inspired by Respect/Validation. Validator.mustBe(Uppercase()).andMust(StartsWith("F")).validate("FOOBAR") ❗ If you w

A framework to validate inputs of text fields and text views in a convenient way.

FormValidatorSwift The FormValidatorSwift framework allows you to validate inputs of text fields and text views in a convenient way. It has been devel

Discover new programming concepts and more new SwiftUI 2 features in this section

Africa-Zoo One thing is sure, we will discover new programming concepts and more new SwiftUI 2 features in this section. TOPICS ARE COVERED: JSON with

Owner
Farshid Ghods
Farshid Ghods
ObjectForm - a simple yet powerful library to build form for your class models.

ObjectForm A simple yet powerful library to build form for your class models. Motivations I found most form libraries for swift are too complicated to

jakehao 175 Nov 2, 2022
The most flexible and powerful way to build a form on iOS

The most flexible and powerful way to build a form on iOS. Form came out from our need to have a form that could share logic between our iOS apps and

HyperRedink 32 Aug 15, 2022
SherlockForms - An elegant SwiftUI Form builder to create a searchable Settings and DebugMenu screens for iOS

??️‍♂️ SherlockForms What one man can invent Settings UI, another can discover i

Yasuhiro Inami 98 Dec 27, 2022
Elegant iOS form builder in Swift

Made with ❤️ by XMARTLABS. This is the re-creation of XLForm in Swift. 简体中文 Overview Contents Requirements Usage How to create a Form Getting row valu

xmartlabs 11.6k Jan 1, 2023
Some cells to Form a Pod

CellsGao Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation CellsGao

null 0 Nov 2, 2021
Custom Field component with validation for creating easier form-like UI from interface builder.

#YALField Custom Field component with validation for creating easier form-like UI from interface builder. ##Example Project To run the example project

Yalantis 476 Sep 1, 2022
Declarative form building framework for iOS

Formalist Swift framework for building forms on iOS Formalist is a Swift framework for building forms on iOS using a simple, declarative, and readable

Seed 159 May 25, 2022
iOS validation framework with form validation support

ATGValidator ATGValidator is a validation framework written to address most common issues faced while verifying user input data. You can use it to val

null 51 Oct 19, 2022
APValidators - Codeless solution for form validation in iOS!

APValidators is a codeless solution for form validation. Just connect everything right in Interface Builder and you're done. Supports really complex and extendable forms by allowing to connect validators in tree.

Alty 131 Aug 16, 2022
TCDInputView is an open source custom input view which is displayed when a text field becomes the first responder.

TCDInputView for iOS TCDInputView is an open source custom input view which is displayed when a text field becomes the first responder. Requirements T

Tom Diggle 7 Apr 25, 2016