Giter VIP home page Giter VIP logo

xlform's Introduction

XLForm

Build Status CocoaPods compatible

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.

We are not implementing any new features for XLForm anymore. However, if a critical issue arises we will fix it.

Purpose

XLForm is the most flexible and powerful iOS library to create dynamic table-view forms. The goal of the library is to get the same power of hand-made forms but spending 1/10 of the time.

XLForm provides a very powerful DSL (Domain Specific Language) used to create a form. It keeps track of this specification on runtime, updating the UI on the fly.

Let's see the iOS Calendar Event Form created using XLForm

Screenshot of native Calendar Event Example

What XLForm does

  • Loads a form based on a declarative form definition.
  • Keeps track of definition changes on runtime to update the form interface accordingly. Further information on Dynamic Forms section of this readme.
  • Supports multivalued sections allowing us to create, delete or reorder rows. For further details see Multivalued Sections section bellow.
  • Supports custom rows definition.
  • Supports custom selectors. For further details of how to define your own selectors check Custom selectors section out.
  • Provides several inline selectors such as date picker and picker inline selectors and brings a way to create custom inline selectors.
  • Form data validation based on form definition.
  • Ability to easily navigate among rows, fully customizable.
  • Ability to show inputAccessoryView if needed. By default a navigation input accessory view is shown.
  • Read only mode for a particular row or the entire form.
  • Rows can be hidden or shown depending on other rows values. This can be done declaratively using NSPredicates. (see Make a row or section invisible depending on other rows values)

How to create a form

Create an instance of XLFormViewController

Swift
class CalendarEventFormViewController : XLFormViewController {

  required init(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    self.initializeForm()
  }


  override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
    self.initializeForm()
  }

  func initializeForm() {
    // Implementation details covered in the next section.
  }

}
Objective-C
#import "XLFormViewController.h"

@interface CalendarEventFormViewController: XLFormViewController

@end
@interface ExamplesFormViewController ()

@end

@implementation ExamplesFormViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self){
        [self initializeForm];
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self){
        [self initializeForm];
    }
    return self;
}

- (void)initializeForm {
  // Implementation details covered in the next section.
}

@end
Implementing the initializeForm method

To create a form we should declare it through a XLFormDescriptor instance and assign it to a XLFormViewController instance. As we said XLForm works based on a DSL that hides complex and boilerplate stuff without losing the power and flexibility of hand-made forms.

To define a form we use 3 classes:

  • XLFormDescriptor
  • XLFormSectionDescriptor
  • XLFormRowDescriptor

A form definition is a XLFormDescriptor instance that contains one or more sections (XLFormSectionDescriptor instances) and each section contains several rows (XLFormRowDescriptor instance). As you may have noticed the DSL structure is analog to the structure of a UITableView (Table -->> Sections -- >> Rows). The resulting table-view form's structure (sections and rows order) mirrors the definition's structure.

Let's see an example implementation of initializeForm to define the iOS Calendar Event Form
- (void)initializeForm {
  XLFormDescriptor * form;
  XLFormSectionDescriptor * section;
  XLFormRowDescriptor * row;

  form = [XLFormDescriptor formDescriptorWithTitle:@"Add Event"];

  // First section
  section = [XLFormSectionDescriptor formSection];
  [form addFormSection:section];

  // Title
  row = [XLFormRowDescriptor formRowDescriptorWithTag:@"title" rowType:XLFormRowDescriptorTypeText];
  [row.cellConfigAtConfigure setObject:@"Title" forKey:@"textField.placeholder"];
  [section addFormRow:row];

  // Location
  row = [XLFormRowDescriptor formRowDescriptorWithTag:@"location" rowType:XLFormRowDescriptorTypeText];
  [row.cellConfigAtConfigure setObject:@"Location" forKey:@"textField.placeholder"];
  [section addFormRow:row];

  // Second Section
  section = [XLFormSectionDescriptor formSection];
  [form addFormSection:section];

  // All-day
  row = [XLFormRowDescriptor formRowDescriptorWithTag:@"all-day" rowType:XLFormRowDescriptorTypeBooleanSwitch title:@"All-day"];
  [section addFormRow:row];

  // Starts
  row = [XLFormRowDescriptor formRowDescriptorWithTag:@"starts" rowType:XLFormRowDescriptorTypeDateTimeInline title:@"Starts"];
  row.value = [NSDate dateWithTimeIntervalSinceNow:60*60*24];
  [section addFormRow:row];

  self.form = form;
}

XLForm will load the table-view form from the previously explained definition. The most interesting part is that it will update the table-view form based on the form definition modifications. That means that we are able to make changes on the table-view form adding or removing section definitions or row definitions to the form definition on runtime and you will never need to care again about NSIndexPath, UITableViewDelegate, UITableViewDataSource or other complexities.

To see more complex form definitions take a look at the example application in the Examples folder of this repository. You can also run the examples on your own device if you wish. XLForm has no dependencies over other pods, anyway the examples project makes use of some cocoapods to show advanced XLForm features.

Using XLForm with Storyboards

  • Perform the steps from How to create a form
  • In Interface Builder (IB), drag-and-drop a UIViewController onto the Storyboard
  • Associate your custom form class to the UIViewController using the Identity Inspector

How to run XLForm examples

  1. Clone the repository [email protected]:xmartlabs/XLForm.git. Optionally you can fork the repository and clone it from your own github account, this approach would be better in case you want to contribute.
  2. Move to either the Objective-c or Swift example folder.
  3. Install example project cocoapod dependencies. From inside Objective-c or Swift example folder run pod install.
  4. Open XLForm or SwiftExample workspace using XCode and run the project. Enjoy!

Rows

Input Rows

Screenshot of Input Examples

Input rows allows the user to enter text values. Basically they use UITextField or UITextView controls. The main differences among the input row types is the keyboardType, autocorrectionType and autocapitalizationType configuration.

static NSString *const XLFormRowDescriptorTypeText = @"text";

Will be represented by a UITextField with UITextAutocorrectionTypeDefault, UITextAutocapitalizationTypeSentences and UIKeyboardTypeDefault.

static NSString *const XLFormRowDescriptorTypeName = @"name";

Will be represented by a UITextField with UITextAutocorrectionTypeNo, UITextAutocapitalizationTypeWords and UIKeyboardTypeDefault.

static NSString *const XLFormRowDescriptorTypeURL = @"url";

Will be represented by a UITextField with UITextAutocorrectionTypeNo, UITextAutocapitalizationTypeNone and UIKeyboardTypeURL.

static NSString *const XLFormRowDescriptorTypeEmail = @"email";

Will be represented by a UITextField with UITextAutocorrectionTypeNo, UITextAutocapitalizationTypeNone and UIKeyboardTypeEmailAddress.

static NSString *const XLFormRowDescriptorTypePassword = @"password";

Will be represented by a UITextField with UITextAutocorrectionTypeNo, UITextAutocapitalizationTypeNone and UIKeyboardTypeASCIICapable. This row type also set the secureTextEntry to YES in order to hide what the user types.

static NSString *const XLFormRowDescriptorTypeNumber = @"number";

Will be represented by a UITextField with UITextAutocorrectionTypeNo, UITextAutocapitalizationTypeNone and UIKeyboardTypeNumbersAndPunctuation.

static NSString *const XLFormRowDescriptorTypePhone = @"phone";

Will be represented by a UITextField with UIKeyboardTypePhonePad.

static NSString *const XLFormRowDescriptorTypeTwitter = @"twitter";

Will be represented by a UITextField with UITextAutocorrectionTypeNo, UITextAutocapitalizationTypeNone and UIKeyboardTypeTwitter.

static NSString *const XLFormRowDescriptorTypeAccount = @"account";

Will be represented by a UITextField with UITextAutocorrectionTypeNo, UITextAutocapitalizationTypeNone and UIKeyboardTypeDefault.

static NSString *const XLFormRowDescriptorTypeInteger = @"integer";

Will be represented by a UITextField with UIKeyboardTypeNumberPad.

static NSString *const XLFormRowDescriptorTypeDecimal = @"decimal";

Will be represented by a UITextField with UIKeyboardTypeDecimalPad.

static NSString *const XLFormRowDescriptorTypeTextView = @"textView";

Will be represented by a UITextView with UITextAutocorrectionTypeDefault, UITextAutocapitalizationTypeSentences and UIKeyboardTypeDefault.

Selector Rows

Selector rows allow us to select a value or values from a list. XLForm supports 8 types of selectors out of the box:

Screenshot of native Calendar Event Example

static NSString *const XLFormRowDescriptorTypeSelectorPush = @"selectorPush";
static NSString *const XLFormRowDescriptorTypeSelectorActionSheet = @"selectorActionSheet";
static NSString *const XLFormRowDescriptorTypeSelectorAlertView = @"selectorAlertView";
static NSString *const XLFormRowDescriptorTypeSelectorLeftRight = @"selectorLeftRight";
static NSString *const XLFormRowDescriptorTypeSelectorPickerView = @"selectorPickerView";
static NSString *const XLFormRowDescriptorTypeSelectorPickerViewInline = @"selectorPickerViewInline";
static NSString *const XLFormRowDescriptorTypeSelectorSegmentedControl = @"selectorSegmentedControl";
static NSString *const XLFormRowDescriptorTypeMultipleSelector = @"multipleSelector";

Normally we will have a collection of object to select (these objects should have a string to display them and a value in order to serialize them), XLForm has to be able to display these objects.

XLForm follows the following rules to display an object:

  1. If the value of the XLFormRowDescriptor object is nil, XLForm uses the noValueDisplayText row property as display text.
  2. If the XLFormRowDescriptor instance has a valueTransformer property value. XLForm uses the NSValueTransformer to convert the selected object to a NSString.
  3. If the object is a NSString or NSNumber it uses the object description property.
  4. If the object conforms to protocol XLFormOptionObject, XLForm gets the display value from formDisplayText method.
  5. Otherwise it return nil. That means you should conforms the protocol :).

You may be interested in change the display text either by setting up noValueDisplayText or valueTransformer property or making the selector options objects to conform to XLFormOptionObject protocol.

This is the protocol declaration:

@protocol XLFormOptionObject <NSObject>

@required
-(NSString *)formDisplayText;
-(id)formValue;

@end

Date & Time Rows

XLForms supports 3 types of dates: Date, DateTime , Time and Countdown Timer and it's able to present the UIDatePicker control in 2 different ways, inline and non-inline.

Screenshot of native Calendar Event Example

static NSString *const XLFormRowDescriptorTypeDateInline = @"dateInline";
static NSString *const XLFormRowDescriptorTypeDateTimeInline = @"datetimeInline";
static NSString *const XLFormRowDescriptorTypeTimeInline = @"timeInline";
static NSString *const XLFormRowDescriptorTypeCountDownTimerInline = @"countDownTimerInline";
static NSString *const XLFormRowDescriptorTypeDate = @"date";
static NSString *const XLFormRowDescriptorTypeDateTime = @"datetime";
static NSString *const XLFormRowDescriptorTypeTime = @"time";
static NSString *const XLFormRowDescriptorTypeCountDownTimer = @"countDownTimer";

Here is an example of how to define these row types:

Objective C

XLFormDescriptor * form;
XLFormSectionDescriptor * section;
XLFormRowDescriptor * row;

form = [XLFormDescriptor formDescriptorWithTitle:@"Dates"];

section = [XLFormSectionDescriptor formSectionWithTitle:@"Inline Dates"];
[form addFormSection:section];

// Date
row = [XLFormRowDescriptor formRowDescriptorWithTag:kDateInline rowType:XLFormRowDescriptorTypeDateInline title:@"Date"];
row.value = [NSDate new];
[section addFormRow:row];

// Time
row = [XLFormRowDescriptor formRowDescriptorWithTag:kTimeInline rowType:XLFormRowDescriptorTypeTimeInline title:@"Time"];
row.value = [NSDate new];
[section addFormRow:row];

// DateTime
row = [XLFormRowDescriptor formRowDescriptorWithTag:kDateTimeInline rowType:XLFormRowDescriptorTypeDateTimeInline title:@"Date Time"];
row.value = [NSDate new];
[section addFormRow:row];

// CountDownTimer
row = [XLFormRowDescriptor formRowDescriptorWithTag:kCountDownTimerInline rowType:XLFormRowDescriptorTypeCountDownTimerInline title:@"Countdown Timer"];
row.value = [NSDate new];
[section addFormRow:row];

Swift

static let dateTime = "dateTime"
static let date = "date"
static let time = "time"

var form : XLFormDescriptor
var section : XLFormSectionDescriptor
var row : XLFormRowDescriptor

form = XLFormDescriptor(title: "Dates") as XLFormDescriptor

section = XLFormSectionDescriptor.formSectionWithTitle("Inline Dates") as XLFormSectionDescriptor
form.addFormSection(section)

// Date
row = XLFormRowDescriptor(tag: tag.date, rowType: XLFormRowDescriptorTypeDateInline, title:"Date")
row.value = NSDate()
section.addFormRow(row)

// Time
row = XLFormRowDescriptor(tag: tag.time, rowType: XLFormRowDescriptorTypeTimeInline, title: "Time")
row.value = NSDate()
section.addFormRow(row)

// DateTime
row = XLFormRowDescriptor(tag: tag.dateTime, rowType: XLFormRowDescriptorTypeDateTimeInline, title: "Date Time")
row.value = NSDate()
section.addFormRow(row)

self.form = form;

Boolean Rows

XLForms supports 2 types of boolean controls:

Screenshot of native Calendar Event Example

static NSString *const XLFormRowDescriptorTypeBooleanCheck = @"booleanCheck";
static NSString *const XLFormRowDescriptorTypeBooleanSwitch = @"booleanSwitch";

We can also simulate other types of Boolean rows using any of the Selector Row Types introduced in the Selector Rows section.

Other Rows

Stepper

XLForms supports counting using UIStepper control:

Screenshot of native Calendar Event Example

static NSString *const XLFormRowDescriptorTypeStepCounter = @"stepCounter";

You can set the stepper paramaters easily:

	row = [XLFormRowDescriptor formRowDescriptorWithTag:kStepCounter rowType:XLFormRowDescriptorTypeStepCounter title:@"Step counter"];
	row.value = @50;
	[row.cellConfigAtConfigure setObject:@YES forKey:@"stepControl.wraps"];
	[row.cellConfigAtConfigure setObject:@10 forKey:@"stepControl.stepValue"];
	[row.cellConfigAtConfigure setObject:@10 forKey:@"stepControl.minimumValue"];
	[row.cellConfigAtConfigure setObject:@100 forKey:@"stepControl.maximumValue"];
Slider

XLForms supports counting using UISlider control:

static NSString *const XLFormRowDescriptorTypeSlider = @"slider";

You can adjust the slider for your own interests very easily:

	row = [XLFormRowDescriptor formRowDescriptorWithTag:kSlider rowType:XLFormRowDescriptorTypeSlider title:@"Slider"];
	row.value = @(30);
	[row.cellConfigAtConfigure setObject:@(100) forKey:@"slider.maximumValue"];
	[row.cellConfigAtConfigure setObject:@(10) forKey:@"slider.minimumValue"];
	[row.cellConfigAtConfigure setObject:@(4) forKey:@"steps"];

Set steps to @(0) to disable the steps functionality.

Info

Sometimes our apps needs to show data that are not editable. XLForm provides us with XLFormRowDescriptorTypeInfo row type to display not editable info. An example of usage would be showing the app version in the settings part of an app.

Button

Apart from data entry rows, not editable rows and selectors, XLForm has a button row XLFormRowDescriptorTypeButton that allows us to do any action when selected. It can be configured using a block (clousure), a selector, a segue identifier, segue class or specifing a view controller to be presented. ViewController specification could be done by setting up the view controller class, the view controller storyboard Id or a nib name. Nib name must match view controller class name.

Multivalued Sections (Insert, Delete, Reorder rows)

Any XLFormSectionDescriptor object can be set up to support row insertion, deletion or reodering. It is possible to enable only one of these modes, a combination or all together. A multivalued section is just a section that support either of these modes.

The most interesting part of multivalued XLFormSectionDescriptor is that it supports all the types of rows that were shown on the Rows section as well as custom rows.

Screenshot of Multivalued Section Example

How to set up a multivalued section

Creating a multivalued section is as simple as use one of the following convenience XLFormSectionDescriptor initializer:

+(id)formSectionWithTitle:(NSString *)title
		   sectionOptions:(XLFormSectionOptions)sectionOptions;
+(id)formSectionWithTitle:(NSString *)title
		   sectionOptions:(XLFormSectionOptions)sectionOptions
		sectionInsertMode:(XLFormSectionInsertMode)sectionInsertMode;

sectionOptions is a bitwise enum parameter that should be used to choose the multivalued section type/s (insert, delete, reorder). Available options are XLFormSectionOptionCanInsert, XLFormSectionOptionCanDelete, XLFormSectionOptionCanReorder. XLFormSectionOptionNone is the value used by default.

sectionInsertMode can be used to select how the insertion mode will look like. XLform has 2 different insertion modes out of the box: XLFormSectionInsertModeLastRow and XLFormSectionInsertModeButton. XLFormSectionInsertModeLastRow is the default value.

Let's see how to create a multivalued section

XLFormDescriptor * form;
XLFormSectionDescriptor * section;
XLFormRowDescriptor * row;

NSArray * nameList = @[@"family", @"male", @"female", @"client"];

form = [XLFormDescriptor formDescriptorWithTitle:@"Multivalued examples"];

// Enable Insertion, Deletion, Reordering
section = [XLFormSectionDescriptor formSectionWithTitle:@"MultiValued TextField"
										  sectionOptions:XLFormSectionOptionCanReorder | XLFormSectionOptionCanInsert | XLFormSectionOptionCanDelete];
section.multivaluedTag = @"textFieldRow";
[form addFormSection:section];

for (NSString * tag in nameList) {
	// add a row to the section, each row will represent a name of the name list array.
	row = [XLFormRowDescriptor formRowDescriptorWithTag:nil rowType:XLFormRowDescriptorTypeText title:nil];
	[[row cellConfig] setObject:@"Add a new tag" forKey:@"textField.placeholder"];
	row.value = [tag copy];
	[section addFormRow:row];
}
// add an empty row to the section.
row = [XLFormRowDescriptor formRowDescriptorWithTag:nil rowType:XLFormRowDescriptorTypeText title:nil];
[[row cellConfig] setObject:@"Add a new tag" forKey:@"textField.placeholder"];
[section addFormRow:row];

Form Values

formValues

You can get all form values invoking -(NSDictionary *)formValues; either XLFormViewController instance or XLFormDescriptor instance.

The returned NSDictionary is created following this rules:

XLForm adds a value for each XLFormRowDescriptor that belongs to a XLFormSectionDescriptor doesn't have a multivaluedTag value set up. The dictionary key is the value of XLFormRowDescriptor tag property.

For each section that has a multivaluedTag value, XLForm adds a dictionary item with a NSArray as a value, each value of the array is the value of each row contained in the section, and the key is the multivaluedTag.

For instance, if we have a section with the multivaluedTag property equal to tags and the following values on the contained rows: 'family', 'male', 'female', 'client', the generated value will be tags: ['family', 'male', 'female', 'client']

httpParameters

In same cases the form value we need may differ from the value of XLFormRowDescriptor instance. This is usually the case of selectors row and when we need to send the form values to some endpoint, the selected value could be a core data object or any other object. In this cases XLForm need to know how to get the value and the description of the selected object.

When using -(NSDictionary *)httpParameters method, XLForm follows the following rules to get XLFormRowDescriptor value:

  1. If the object is a NSString, NSNumber or NSDate, the value is the object itself.
  2. If the object conforms to protocol XLFormOptionObject, XLForm gets the value from formValue method.
  3. Otherwise it return nil.

multivaluedTag works in the same way as in formValues method.

How to create a Custom Row

To create a custom cell you need to create a UITableViewCell extending from XLFormBaseCell. XLFormBaseCell conforms to XLFormDescriptorCell protocol.

You may be interested in implement XLFormDescriptorCell methods to change the cell behaviour.

@protocol XLFormDescriptorCell <NSObject>

@required

@property (nonatomic, weak) XLFormRowDescriptor * rowDescriptor;

// initialise all objects such as Arrays, UIControls etc...
-(void)configure;
// update cell when it about to be presented
-(void)update;

@optional

// height of the cell
+(CGFloat)formDescriptorCellHeightForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor;
// called to check if cell can became first responder
-(BOOL)formDescriptorCellCanBecomeFirstResponder;
// called to ask cell to assign first responder to relevant UIView.
-(BOOL)formDescriptorCellBecomeFirstResponder;
// called when cell is selected
-(void)formDescriptorCellDidSelectedWithFormController:(XLFormViewController *)controller;
// http parameter name used for network request
-(NSString *)formDescriptorHttpParameterName;

// is invoked when cell becomes firstResponder, could be used for change how the cell looks like when it's the forst responder.
-(void)highlight;
// is invoked when cell resign firstResponder
-(void)unhighlight;


@end

Once a custom cell has been created you need to let XLForm know about this cell by adding the row definition to cellClassesForRowDescriptorTypes dictionary.

[[XLFormViewController cellClassesForRowDescriptorTypes] setObject:[MYCustomCellClass class] forKey:kMyAppCustomCellType];

or, in case we have used nib file to define the XLBaseDescriptorCell:

[[XLFormViewController cellClassesForRowDescriptorTypes] setObject:@"nibNameWithoutNibExtension" forKey:kMyAppCustomCellType];

Doing that, XLForm will instantiate the proper cell class when kMyAppCustomCellType row type is used.

Custom Selectors - Selector Row with a custom selector view controller

Almost always the basic selector which allows the user to select one or multiple items from a pushed view controller is enough for our needs, but sometimes we need more flexibility to bring a better user experience to the user or do something not supported by default.

Let's say your app user needs to select a map coordinate or it needs to select a value fetched from a server endpoint. How do we do that easily?

Screenshot of Map Custom Selector

Define the previous selector row is as simple as ...

row = [XLFormRowDescriptor formRowDescriptorWithTag:kSelectorMap rowType:XLFormRowDescriptorTypeSelectorPush title:@"Coordinate"];
// set up the selector controller class
row.action.viewControllerClass = [MapViewController class];
// or
//row.action.viewControllerStoryboardId = @"MapViewControllerStoryboardId";
// or
//row.action.viewControllerNibName = @"MapViewControllerNibName";

// Set up a NSValueTransformer to convert CLLocation to NSString, it's used to show the select value description (text).
row.valueTransformer = [CLLocationValueTrasformer class];
// Set up the default value
row.value = [[CLLocation alloc] initWithLatitude:-33 longitude:-56];

action.viewControllerClass controller class should conform to XLFormRowDescriptorViewController protocol.

In the example above, MapViewController conforms to XLFormRowDescriptorViewController.

@protocol XLFormRowDescriptorViewController <NSObject>

@required
@property (nonatomic) XLFormRowDescriptor * rowDescriptor;

@end

XLForm sets up rowDescriptor property using the XLFormRowDescriptor instance that belongs to the selector row.

The developer is responsible for update its views with the rowDescriptor value as well as set the selected value to rowDescriptor from within the custom selector view controller.

Note: the properties viewControllerClass, viewControllerNibName or viewControllerStoryboardId are mutually exclusive and are used by XLFormButtonCell and XLFormSelectorCell. If you create a custom cell then you are responsible for using them.

Another example

Screenshot of Dynamic Custom Selector

row = [XLFormRowDescriptor formRowDescriptorWithTag:kSelectorUser rowType:XLFormRowDescriptorTypeSelectorPush title:@"User"];
row.action.viewControllerClass = [UsersTableViewController class];

You can find the details of these examples within the example repository folder, Examples/Objective-C/Examples/Selectors/CustomSelectors/ and Examples/Objective-C/Examples/Selectors/DynamicSelector.

Dynamic Forms - How to change the form dynamically at runtime

Any change made on the XLFormDescriptor will be reflected on the XLFormViewController tableView. That means that when a section or a row is added or removed XLForm will animate the section or row accordingly.

We shouldn't have to deal with NSIndexPaths or add, remove UITableViewCell anymore. NSIndexPath of a specific TableViewCell changes along the time and this makes very hard to keep track of the NSIndexPath of each UITableViewCell.

Each XLForm XLFormRowDescriptor row has a tag property that is set up in its constructor. XLFormDescriptor has, among other helpers, an specific one to get a XLFormRowDescriptor from a tag. It's much easier to manage XLFormRowDescriptors using tags, the tag should be unique and it doesn't change on tableview additions modifications or deletions.

It's important to keep in mind that all the UITableView form modifications have to be made using the descriptors and not making modifications directly on the UITableView.

Usually you may want to change the form when some value change or some row or section is added or removed. For this you can set the disabled and hidden properties of the rows or sections. For more details see Make a row or section invisible depending on other rows values.

In order to stay in sync with the form descriptor modifications your XLFormViewController subclass should override the XLFormDescriptorDelegate methods of 'XLFormViewController'.

Note: It is important to always call the [super ...] method when overriding this delegate's methods.

@protocol XLFormDescriptorDelegate <NSObject>

@required

-(void)formSectionHasBeenRemoved:(XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index;
-(void)formSectionHasBeenAdded:(XLFormSectionDescriptor *)formSection atIndex:(NSUInteger)index;
-(void)formRowHasBeenAdded:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath;
-(void)formRowHasBeenRemoved:(XLFormRowDescriptor *)formRow atIndexPath:(NSIndexPath *)indexPath;
-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)formRow oldValue:(id)oldValue newValue:(id)newValue;
-(void)formRowDescriptorPredicateHasChanged:(XLFormRowDescriptor *)formRow
                                   oldValue:(id)oldValue
                                   newValue:(id)newValue
                              predicateType:(XLPredicateType)predicateType;

@end

For instance if we want to show or hide a row depending on the value of another row:

-(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
{
	// super implmentation MUST be called
	[super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
    if ([rowDescriptor.tag isEqualToString:@"alert"]){
        if ([[rowDescriptor.value valueData] isEqualToNumber:@(0)] == NO && [[oldValue valueData] isEqualToNumber:@(0)]){
            XLFormRowDescriptor * newRow = [rowDescriptor copy];
            [newRow setTag:@"secondAlert"];
            newRow.title = @"Second Alert";
            [self.form addFormRow:newRow afterRow:rowDescriptor];
        }
        else if ([[oldValue valueData] isEqualToNumber:@(0)] == NO && [[newValue valueData] isEqualToNumber:@(0)]){
            [self.form removeFormRowWithTag:@"secondAlert"];
        }
    }

Make a row or section invisible depending on other rows values

Summary

XLForm allows you to define dependencies between rows so that if the value of one row is changed, the behaviour of another one changes automatically. For example, you might have a form where you question the user if he/she has pets. If the answer is 'yes' you might want to ask how their names are. So you can make a row invisible and visible again based on the values of other rows. The same happens with sections. Take a look at the following example:

Screenshot of hiding rows

Of course, you could also do this manually by observing the value of some rows and deleting and adding rows accordingly, but that would be a lot of work which is already done.

How it works

To make the appearance and disappearance of rows and sections automatic, there is a property in each descriptor:

@property id hidden;

This id object will normally be a NSPredicate or a NSNumber containing a BOOL. It can be set using any of them or eventually a NSString from which a NSPredicate will be created. In order for this to work the string has to be syntactically correct.

For example, you could set the following string to a row (second) to make it disappear when a previous row (first) contains the value "hide".

second.hidden = [NSString stringWithFormat:@"$%@ contains[c] 'hide'", first];

This will insert the tag of the first after the '$', you can do that manually as well, of course. When the predicate is evaluated every tag variable gets substituted by the corresponding row descriptor.

When the argument is a NSString, a '.value' will be appended to every tag unless the tag is followed by '.isHidden' or '.isDisabled'. This means that a row (or section) might depend on the value or the hidden or disabled properties of another row. When the property is set with a NSPredicate directly, its formatString will not be altered (so you have to append a '.value' after each variable if you want to refer to its value). Setting a NSString is the simplest way but some complex predicates might not work so for those you should directly set a NSPredicate.

You can also set this properties with a bool object which means the value of the property will not change unless manually set.

To get the evaluated boolean value the isHidden method should be called. It will not re-evaluate the predicate each time it gets called but just when the value (or hidden/disabled status) of the rows it depends on changes. When this happens and the return value changes, it will automagically reflect that change on the form so that no other method must be called.

Here is another example, this time a bit more complex:

Screenshot of hiding rows

Disabling rows (set to read-only mode)

Rows can be disabled so that the user can not change them. By default disabled rows have a gray text color. To disable a row the only thing that has to be done is setting its disabled property:

@property id disabled;

This property expects a NSNumber containing a BOOL, a NSString or a NSPredicate. A bool will statically disable (or enable the row). The other two work just like the hidden property explained in the section above. This means a row can be disabled and enabled depending on the values of other rows. When a NSString is set, a NSPredicate will be generated taking the string as format string so that it has to be consistent for that purpose.

A difference to the hidden property is that checking the disabled status of a row does not automatically reflect that value on the form. Tharefore, the XLFormViewController's updateFormRow method should be called.

Validations

We can validate the form data using XLForm validation support.

Each XLFormRowDescriptor instance contains a list of validators. We can add validators, remove validators and validate a particular row using these methods:

-(void)addValidator:(id<XLFormValidatorProtocol>)validator;
-(void)removeValidator:(id<XLFormValidatorProtocol>)validator;
-(XLFormValidationStatus *)doValidation;

We can define our own custom validators just defining a object that conforms to XLFormValidatorProtocol.

@protocol XLFormValidatorProtocol <NSObject>

@required

-(XLFormValidationStatus *)isValid:(XLFormRowDescriptor *)row;

@end

XLFormRegexValidator is an example of a validator we can create.

A very common validation is ensuring that a value is not empty or nil. XLFom exposes required XLFormRowDescriptor property to specify required rows.

To get all rows validation errors we can invoke the following XLFormViewController method:

-(NSArray *)formValidationErrors;

Additional configuration of Rows

XLFormRowDescriptor allow us to configure generic aspects of a UITableViewCell, for example: the rowType, the label, the value (default value), if the cell is required, hidden or disabled, and so on.

You may want to set up another properties of the UITableViewCell. To set up another properties XLForm makes use of Key-Value Coding allowing the developer to set the cell properties by keyPath.

You just have to add the properties to cellConfig or cellConfigAtConfigure dictionary property of XLFormRowDescriptor. The main difference between cellConfig and cellConfigAtConfigure is the time when the property is set up. cellConfig properties are set up each time a cell is about to be displayed. cellConfigAtConfigure, on the other hand, set up the property just after the init method of the cell is called and only one time.

Since version 3.3.0 you can also use cellConfigForSelector to configure how the cells of the XLFormOptionsViewController look like when it is shown for a selector row.

For instance if you want to set up the placeholder you can do the following:

row = [XLFormRowDescriptor formRowDescriptorWithTag:@"title" rowType:XLFormRowDescriptorTypeText];
[row.cellConfigAtConfigure setObject:@"Title" forKey:@"textField.placeholder"];
[section addFormRow:row];

Let's see how to change the color of the cell label:

Objective C

row = [XLFormRowDescriptor formRowDescriptorWithTag:@"title" rowType:XLFormRowDescriptorTypeText];
[row.cellConfig setObject:[UIColor redColor] forKey:@"textLabel.textColor"];
[section addFormRow:row];

Swift

row = XLFormRowDescriptor(tag: "title", rowType: XLFormRowDescriptorTypeText, title: "title")
row.cellConfig.setObject(UIColor.blackColor(), forKey: "backgroundColor")
row.cellConfig.setObject(UIColor.whiteColor(), forKey: "textLabel.textColor")
section.addFormRow(row)

FAQ

How to customize the header and/or footer of a section

For this you should use the UITableViewDelegate methods in your XLFormViewController. This means you should implement one or both of these:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

Also you might want to implement the following methods to specify the height for these views:

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

How to assign the first responder on form appearance

Assign the first responder when the form is shown is as simple as setting the property assignFirstResponderOnShow to YES. By default the value of the property is NO.

@property (nonatomic) BOOL assignFirstResponderOnShow;

How to set a value to a row.

You should set the value property of XLFormRowDescriptor relevant instance.

@property (nonatomic) id value;

You may notice that the value property type is id and you are the responsable to set a value with the proper type. For instance, you should set a NSString value to a XLFormRowDescriptor instance of XLFormRowDescriptorTypeText.

You may have to update the cell to see the UI changes if the row is already presented. -(void)reloadFormRow:(XLFormRowDescriptor *)formRow method is provided by XLFormViewController to do so.

How to set the default value to a row.

You should do the same as How to set a value to a row.

How to set up the options to a selector row.

XLForm has several types of selectors rows. Almost all of them need to know which are the values to be selected. For a particular XLFormRowDescriptor instance you specify these values setting a NSArray instance to selectorOptions property.

@property NSArray * selectorOptions;

How to get form values

If you want to get the raw form values you should call formValues method of XLFormDescriptor. Doing that you will get a dictionary containing all the form values. tag property value of each row is used as dictionary key. Only XLFormROwDescriptor values for non nil tag values are added to the dictionary.

You may be interested in the form values to use it as enpoint parameter. In this case httpParameters would be useful.

If you need something different, you can iterate over each row...

Objective C

 NSMutableDictionary * result = [NSMutableDictionary dictionary];
 for (XLFormSectionDescriptor * section in self.form.formSections) {
     if (!section.isMultivaluedSection){
         for (XLFormRowDescriptor * row in section.formRows) {
             if (row.tag && ![row.tag isEqualToString:@""]){
                 [result setObject:(row.value ?: [NSNull null]) forKey:row.tag];
             }
         }
     }
     else{
         NSMutableArray * multiValuedValuesArray = [NSMutableArray new];
         for (XLFormRowDescriptor * row in section.formRows) {
             if (row.value){
                 [multiValuedValuesArray addObject:row.value];
             }
         }
         [result setObject:multiValuedValuesArray forKey:section.multivaluedTag];
     }
 }
 return result;

Swift

var results = [String:String]()
if let fullName = form.formRowWithTag(tag.fullName).value as? String {
    results[tag.fullName] = fullName
}

How to change UITextField length

You can change the length of a UITextField using the cellConfigAtConfigure dictionary property. This value refers to the percentage in relation to the table view cell.

Objective C

[row.cellConfigAtConfigure setObject:[NSNumber numberWithFloat:0.7] forKey:XLFormTextFieldLengthPercentage];

Swift

row.cellConfigAtConfigure.setObject(0.7, forKey:XLFormTextFieldLengthPercentage)

**Note:**The same can be achieved for the UITextView when using XLFormRowDescriptorTypeTextView; just set your percentage for the key XLFormTextViewLengthPercentage.

How to change a UITableViewCell font

You can change the font or any other table view cell property using the cellConfig dictionary property. XLForm will set up cellConfig dictionary values when the table view cell is about to be displayed.

Objective C

[row.cellConfig setObject:[UIColor greenColor] forKey:@"textLabel.textColor"];
[row.cellConfig setObject:[UIFont fontWithName:FONT_LATO_REGULAR size:12.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:[UIFont fontWithName:FONT_LATO_REGULAR size:12.0] forKey:@"detailTextLabel.font"];

Swift

row.cellConfig.setObject(UIColor.whiteColor(), forKey: "self.tintColor")
row.cellConfig.setObject(UIFont(name: "AppleSDGothicNeo-Regular", size: 17)!, forKey: "textLabel.font")
row.cellConfig.setObject(UIColor.whiteColor(), forKey: "textField.textColor")
row.cellConfig.setObject(UIFont(name: "AppleSDGothicNeo-Regular", size: 17)!, forKey: "textField.font")

For further details, please take a look at UICustomizationFormViewController.m example.

How to set min/max for date cells?

Each XLFormDateCell has a minimumDate and a maximumDate property. To set a datetime row to be a value in the next three days you would do as follows:

Objective C

[row.cellConfigAtConfigure setObject:[NSDate new] forKey:@"minimumDate"];
[row.cellConfigAtConfigure setObject:[NSDate dateWithTimeIntervalSinceNow:(60*60*24*3)] forKey:@"maximumDate"];

Swift

row.cellConfig.setObject(NSDate(), forKey: "maximumDate")

How to disable the entire form (read only mode).

disable XLFormDescriptor property can be used to disable the entire form. In order to make the displayed cell to take effect we should reload the visible cells ( [self.tableView reloadData] ). Any other row added after form disable property is set to YES will reflect the disable mode automatically (no need to reload table view).

How to hide a row or section when another rows value changes.

To hide a row or section you should set its hidden property. The easiest way of doing this is by setting a NSString to it. Let's say you want a section to hide if a previous row, which is a boolean switch, is set to 1 (or YES). Then you would do something like this:

section.hidden = [NSString stringWithFormat:@"$%@ == 1", previousRow];

That is all!

What do I have to do to migrate from version 2.2.0 to 3.0.0?

The only thing that is not compatible with older versions is that the disabled property of the XLFormRowDescriptor is an id now. So you just have to add @ before the values you set to it like this:

row.disabled = @YES; // before: row.disabled = YES;

How to change input accessory view (navigation view)

Overriding inputAccessoryViewForRowDescriptor: XLFormViewController method. If you want to disable it completely you can return nil. But you can also customize its whole appearance here.

- (UIView *)inputAccessoryViewForRowDescriptor:(XLFormRowDescriptor *)rowDescriptor
{
      return nil; //will hide it completely
      // You can use the rowDescriptor parameter to hide/customize the accessory view for a particular rowDescriptor type.
}

How to set up a pushed view controller?

The view controller that will be pushed must conform to the XLFormRowDescriptorViewController protocol which consists of the following property:

@property (nonatomic) XLFormRowDescriptor * rowDescriptor;

This rowDescriptor refers to the selected row of the previous view controller and will be set before the transition to the new controller so that it will be accessible for example in its viewDidLoad method. That is where that view controller should be set up.

How to change the default appearance of a certain cell

The best way to do this is to extend the class of that cell and override its update and/or configure methods. To make this work you should also update the cellClassesForRowDescriptorTypes dictionary in your subclass of XLFormViewController by setting your custom class instead of the class of the cell you wanted to change.

How to change the returnKeyType of a cell

To change the returnKeyType of a cell you can set the returnKeyType and nextReturnKeyType properties. The former will be used if there is no navigation enabled or if there is no row after this row. In the other case the latter will be used. If you create a custom cell and want to use these you should conform to the XLFormReturnKeyProtocol protocol. This is how you can set them:

[row.cellConfigAtConfigure setObject:@(UIReturnKeyGo) forKey:@"nextReturnKeyType"];

How to change the height of one cell

If you want to change the height for all cells of one class you should subclass that cell and override the class method formDescriptorCellHeightForRowDescriptor. If you want to change the height of one individual cell then you can set that height to the height property of XLFormRowDescripto like this:

XLFormRowDescriptor* row = ...
row.height = 55;

How to change the appearance of the cells of a selector view controller (XLFormOptionsViewController)

To change the appearance of the cells of a XLFormOptionsViewController you can use the cellConfigForSelector property on the row descriptor. Example:

[row.cellConfigForSelector setObject:[UIColor redColor] forKey:@"textLabel.textColor"];

How to limit the characters of a XLFormTextFieldCell or a XLFormTextViewCell

You can make this happen using the textFieldMaxNumberOfCharacters and the textViewMaxNumberOfCharacters respectively.

[row.cellConfigAtConfigure setObject:@(20) forKey:@"textViewMaxNumberOfCharacters"];

Installation

Swift Package Manager

Starting with Xcode 11, Swift Package Manager is the recommended and preferred way for installing dependencies in Xcode projects. Installing dependencies via SwiftPM does not require the application nor dependencies to be written in Swift.

To add XLForm to your project using SwiftPM follow these steps:

  1. Open your project in Xcode
  2. In the main menu, select File -> Swift Packages -> Add Package Dependency...
  3. In the window, enter the package url https://github.com/xmartlabs/XLForm
  4. Configure the version to be used

To use XLForm in your code, import the module or header files as needed:

#import "XLForm.h"  // Obj-c
import XLForm       // Swift

CocoaPods

  1. Add the following line in the project's Podfile file: pod 'XLForm', '~> 4.3'.
  2. Run the command pod install from the Podfile folder directory.

XLForm has no dependencies over other pods.

How to use master branch

Often master branch contains most recent features and latest fixes. On the other hand this features was not fully tested and changes on master may occur at any time. For the previous reasons I stongly recommend to fork the repository and manage the updates from master on your own making the proper pull on demand.

To use xmartlabs master branch.....

pod 'XLForm', :git => 'https://github.com/xmartlabs/XLForm.git'

You can replace the repository URL for your forked version url if you wish.

How to use XLForm in Swift files

If you have installed XLForm with cocoapods and have set use_frameworks! in your Podfile, you can add import XLForm to any Swift file.

If you are using cocoapods but have not set use_frameworks! in your Podfile, add #import <XLForm/XLForm.h> to your bridging header file.

For further details on how to create and configure the bridging header file visit Importing Objective-C into Swift.

Carthage

In your Cartfile add:

github "xmartlabs/XLForm" ~> 4.2

Using git submodules

  • Clone XLForm as a git submodule by running the following command from your project root git folder.
$ git submodule add https://github.com/xmartlabs/XLForm.git
  • Open XLForm folder that was created by the previous git submodule command and drag the XLForm.xcodeproj into the Project Navigator of your application's Xcode project.

  • Select the XLForm.xcodeproj in the Project Navigator and verify the deployment target matches with your application deployment target.

  • Select your project in the Xcode Navigation and then select your application target from the sidebar. Next select the "General" tab and click on the + button under the "Embedded Binaries" section.

  • Select XLForm.framework and we are done!

Requirements

  • ARC
  • iOS 9.0 and above
  • Xcode 9.0+ (11.0+ for installation via Swift Package Manager)

Release Notes

Have a look at the CHANGELOG

Author

Martin Barreto (@mtnBarreto)

Contact

Any suggestion or question? Please create a Github issue or reach us out.

xmartlabs.com (@xmartlabs)

xlform's People

Contributors

3a4ot avatar albsala avatar bazik123 avatar bigsprocket avatar bojan avatar drusy avatar ericcgu avatar flashspys avatar florianbuerger avatar hankinsoft avatar jimmyti avatar jschmid avatar julienpouget avatar kevindeleon avatar kiancheong avatar kishinmanglani avatar koenpunt avatar liraz avatar m-revetria avatar mats-claassen avatar mimo42 avatar mtnbarreto avatar papo2608 avatar pastorin avatar schemetrical avatar shams-ahmed avatar siarheifedartsou avatar tobihagemann avatar tommypeps avatar tomtaylor 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  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

xlform's Issues

Consider wiring in US2FormValidator

We use US2FormValidator internally and have built a number of add-on validations/conditions beyond the framework's extensive built-in options. I highly recommend it as a means of effectively extending XLForm's validation capabilities without a lot of labor.

ButtonCell doesn’t deselect table row

Any way to deselect the table row once a button is pressed. When I press a button, I need to check some other table rows and may not launch a view controller. In that case I open an alert but must also clear the ‘press’ / ‘selected’ state and can’t see how to.
Thx

Send event each time a value is selected in the picker displayed by row of type XLFormRowDescriptorTypeSelectorPickerViewInline

Hi,

First of all, I would like to warmly thanks those which created/contributed to this amazing library !

For my needs, I would like to handle when a user click on a row from the UIPickerView displayed by cell of type XLFormRowDescriptorTypeSelectorPickerViewInline.

After some research of the functioning of the XLFormInlineSelectorCell classe I didn't find any mechanism to allow me to handle the click event of a user on a value inside the UIPickerView.

My question is, should I create a subclass of XLFormInlineSelectorCell and override the update method to send an event to my main viewcontroller or call a delegate method to my main viewcontroller or is there a better way of doing this ?

Thanks !

AFNetworking 1.3.0

XLForm seems to be a great library. I'm not able to use it because RestKit requires AFNetworking 1.3.0 and XLForm minimal 2. Is it possible to support the older AFNetworking version, or a subversion of XLForms without the XLDataLoader?

[Enhancement] Move Cell Initialization into Separate Methods

Currently, all the 'setup' code for an XLForm cell is located inside the 'init' methods. This can cause issues when trying to use a category to modify the cell class. Most of the 'init' methods are themselves category methods. As a result, calls to [super initWithX] have no effect.

This issue could be avoided by moving the actual logic of setting up the cell into a separate method call. Categories and Subclasses would then be able to override this method rather than having to override init.

P.S. The 'dealloc' method would also be a good candidate for this type of change.

Does XLForm support combo-box type field?

I've played around with this library, and must say it's saved me hours! So, thank you for building this.

I was trying to create a combo-box that allows user to select one of the 50 US states. However, from what I could gather, it seems XLForm does not support a combo-box. Is it something that you can add soon? If not, can you please give me some pointers as to how to implement this on my own?

Thanks!

Transparent Background Color PickerView

If i click on datetime field then the picker shown to me at the bottom of the screen is transparent if i click on any textfield and then go back to any pickerview related field then it's background color changed from transparent to white.

Reordering Cell

I'm wondering if it has the functionality to reorder the row in a table view, Or you have any plans to do it in near future?

Button Done in UITextField

Hi,

I would like to set a Done button in an UITextField.

I tried this:

        let row = XLFormRowDescriptor(tag : name, rowType : type)

        row.cellConfigAtConfigure.setObject(placeholder, forKey: "textField.placeholder")
        row.cellConfigAtConfigure.setObject(UIReturnKeyType.Done.toRaw(), forKey: "textField.returnKeyType")
        row.required = !optional

But the XLForm SIGABRT in XLFormRowDescriptor at line 69 in cellForFormController method:

[_cell setValue:value forKeyPath:keyPath];

Side by Side Text Fields

Perhaps shorter text fields for things like city and state and zip, or for an expiration date and cvc code. That would be cool.

Where is the Delete button?

I upgraded from 1.0.1 to 2.0.0 and "Delete" button dissapeared.

[self setShowDeleteButton:YES];  is not working?

Whats the current way to manage the dissapeared feature?

support ios 6 version

How to make support ios 6 version?
I removed some libraries from pods, but still have lots of error.

Font Size

What's the rationale behind having such a tiny font size for the title and text labels?

I don't know about you but that's basically the only thing that your calendar add event example differs in when compared to the original screen.

Why isn't UIFontTextStyleBody the default value in XLFormDescriptorCell -update methods on your cells instead of UIFontTextStyleHeadline? Should drop the "Bold" trait as well in order to reproduce iOS defaults.

Am I missing something?

Image Picker

Hi,
Image Picker disappeared in V2.0.
Any plan to bring it back?
Regards

Swift problem

Hi,

I'm new with XLForm. I'm trying to use constant XLFormRowDescriptorTypeSelectorPickerView but I have a compiler error:

Undefined symbols for architecture x86_64:
"_XLFormRowDescriptorTypeSelectorPickerView", referenced from:
_TFC12TrocaTudo30NovaOfertaXLFormViewController13initalizeFormfS0_FT_T in NovaOfertaXLFormViewController.o
ld: symbol(s) not found for architecture x86_64

I have put the imports above in my Bridging-Header.h:

import <XLForm/XLForm.h>

import <XLForm/XLFormViewController.h>

The xCode autocomplete is working fine and all the XLForm's classes are being recognized.

Any tip?

Thank you!

Crash with "not really" optional protocol methods

the -(void)configureDataManager:(XLFormDataManager *)dataManager; declared in XLFormViewControllerDelegate is optional but no test is made to ensure it exists...

Results in a crash.

Eg: XLFormViewController line 591

initWithCoder support

I'm using segues on my project. Navigation is performed using code like

[self performSegueWithIdentifier:@"editData" sender:self];

And the data to be edited is asigned to destination view controller on the prepareForSeguemethod

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"editWorkerProfile"])
    {
        UINavigationController* navController = [segue destinationViewController];
        MyEditorViewController *editorController = (MyEditorViewController *) [navController topViewController];
        editorController.data = dataToBeEdited;
    }
}

The destination ViewController is initialized using "initWithCoder" and form structure is created on the "viewDidLoad" (Because data property is assigned after initialization).

With te "1.0.0" version of XLForm I used a "trick" like this on destination ViewController:

- (id)initWithCoder:(NSCoder*)aDecoder
{
    if(self = [super initWithCoder:aDecoder])
    {
        XLFormDescriptor * form  = [XLFormDescriptor formDescriptorWithTitle:@"work profile"];
        return [super initWithForm:form]; // Second init... it works with XLFrom 1.0.0!!!
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Form content is built after initialization
    [self buildForm: self.form withData: self.data]; 
}

With the actual git XLForm version this code is not working anymore: form appears empty...

¿What's the correct way to use XLForm with storyboard & segues?

Not really an issue

Just wanted to say thanks for the library - saved me hours this weekend. I only just realised how recently you released it, so I thought I'd pop in and let you know that I'm using it and it worked really well.

The only issue I've had is with the label for a selector field not updating, but I'll create a proper issue at some point with more details.

Cheers!

Row value assigned too late, otherwise nil

First of all, I'd like to thank you for this wonderful library. Great work 👍

Now about the issue:

Let's say I have a text field cell. Unless the focus moves away from the text field (ie: the keyboard has been dismissed or the user went to the next text field), [[self.form formRowWithTag:@"title"] value] returns nil regardless of the contents of the text field. That would be wrong if the text field's text is not empty. So consider this scenario:

  1. The user taps on the text field
  2. The user enters a value
  3. The user taps on the "Done" button

At this point, there is a problem because the value of the text field is nil even though it shouldn't be.

inline date picker with minuteInterval/minimumDate/maximumDate

I need to set min/max dates and an interval for the selection. I can't seem to figure out how to do this with the current master branch. I've added some properties to XLFormDateCell to control these and updated setModeToDatePicker: to set the options on the date picker.

-(void)setModeToDatePicker:(UIDatePicker *)datePicker
{
    if ((([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeDateInline] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeDate]) && self.formDatePickerMode == XLFormDateDatePickerModeGetFromRowDescriptor) || self.formDatePickerMode == XLFormDateDatePickerModeDate){
        datePicker.datePickerMode = UIDatePickerModeDate;
    }
    else if ((([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTimeInline] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTime]) && self.formDatePickerMode == XLFormDateDatePickerModeGetFromRowDescriptor) || self.formDatePickerMode == XLFormDateDatePickerModeTime){

        datePicker.datePickerMode = UIDatePickerModeTime;
    }
    else{
        datePicker.datePickerMode = UIDatePickerModeDateAndTime;
    }

    if (self.minuteInterval)
        datePicker.minuteInterval = self.minuteInterval;

    if (self.minimumDate)
        datePicker.minimumDate = self.minimumDate;

    if (self.maximumDate)
        datePicker.maximumDate = self.maximumDate;

}

Then in my form setup I can do this to get the desired effect:

row = [XLFormRowDescriptor formRowDescriptorWithTag:@"ends" rowType:XLFormRowDescriptorTypeTimeInline title:@"Ends"];
row.value = [NSDate dateWithTimeIntervalSinceNow:60*60*25];
XLFormDateCell * dateEndCell = (XLFormDateCell *)[row cellForFormController:self];
dateEndCell.minuteInterval = 15;
dateEndCell.minimumDate = start;

If there is another way to do this without modifying the XLForm code, let me know. If this feature isn't currently supported and my solution seems acceptable to you, I can submit a pull request.

screenshot_835

Date picker causes crash

Run the demo, select the calendaring event item (first one). Click "starts" and then click the row again to hide. Click the cancel button. Click "Text Field Examples" in the main screen. It will crash all the time in the simulator. Both 32 and 64 bits iOS 7.1

Disable state on rows not working when changed programmatically

I'm using v2.0.0 and I want to change the disable state of my rows programmatically without reloading the view. But when I do this the rows stay in their previous state. This happens both when I set disabled to YES or to NO.

Once I change the view or scroll the table view down so that some rows are not visible any more and I scroll back then those rows that were invisible for a moment are correctly disabled/enabled.

How can I make everything work without the need to scroll? Any workaround for me to quick-fix this thing? Also I think this is an issue with XLForm and should be fixed within the framework long-term.

Here are three screenshots, when I change the state of the "Availability" switch then all other rows should get enabled/disabled. On the first screenshot everything is fine. On the second I have enabled the switch so everything else should be disabled but it doesn't work. And on the third one you can see the state after scrolling down and up again.

ios simulator bildschirmfoto 08 07 2014 19 06 17
ios simulator bildschirmfoto 08 07 2014 19 06 23
ios simulator bildschirmfoto 08 07 2014 19 06 37

Thank you for your help!

Using the 'Done' and 'Cancel' Buttons with a Storyboard?

This library looks fantastic so far but I'm having trouble figuring out how to add a form to an existing application. The flow I want is user taps a control -> Form is displayed in a Modal dialog with the cancel and done buttons displayed. Since the segue from the main screen to the form dialog is defined in the storyboard, there is no 'hook' where I can manually inititalize the NavigationController class. The 'init' methods of the controller classes never get called when using a storyboard, so how do I set up my form?

new cocoapod pls

Hi there...
Custom rows and step counter are really nice features that solve manually "patches" I actually use over 1.0.0 version... is there any plan to publish as pod a new version?

Thanks a lot

can i set custom row click event?

hi,
can i set my custom row click event?
i try to set the tableview 'didSelectRowAtIndexPath' delegate,
then all xlform row's click event is can't work.
how can i to do these ?
thanks very much:)

Undefined symbols for architecture i386 with NSString XLFormRowDescriptorType in a Swift project

Hi,

I'm using XLForm with Cocoapods in a project developed in Swift and Objective-C.

I tried to use key as XLFormRowDescriptorTypeButton (from XLForm.h) into my Swift files but when I try to compile, I have those errors:

Undefined symbols for architecture i386:
  "_XLFormRowDescriptorTypeButton", referenced from:
      __TFC7MyProject26LoginAccountViewController26_getXLFormTypeForInputTypefS0_FSiGSqSS_ in LoginAccountViewController.o

Any suggestion ?

Autoformatting of typed text in text fields?

It'd be nice to be able to apply autoformatters to text fields.

For example, if I'm typing a phone number, i want 1234567890 to automatically become (123)456-7890.

Or in field with mm/yy have 0119 automatically become 01/19

Updating Row Data

Is there any way to dynamically update the value of a row? I have a project where the data for my form is coming from an asynchronous call which prevents me from simply setting the value of each row during the form creation. My initial thought was to lookup each row by tag after I get my data and set row.value to the appropriate model value. As far as I can tell though, changing 'row.value' doesn't actually update the text in the cell. Is there something I'm missing here or is there simply no way to do this right now?

cannot input chinese charactor

hi martin,
i want to use xlform in my ios app.
this is very easy & helpful to draw complex form.
but when i run the demo.
the text input cannot input chinese.
is there have setting to set this?

thasnk~~

XLFormRowDescriptorTypeSelectorPickerViewInline not available in Version 1.0.1 (current)

I am trying to implement an inline map view with XLForm like in the following screenshot:

bildschirmfoto 2014-06-25 um 18 13 24

But for some reason I can't use the XLFormRowDescriptorTypeSelectorPickerViewInline mode to implement the map inline. There's isn't even an autocompletion for it. Was it removed? Why? I need it here ... thank you for any help. Great framework apart from that! Love it. :)

Ipad Support

How to increase font size and cell size for iPad? in iPad it is looking so small fonts and small row height.

row validation is not performed for "unrendered" row cells.

I have a "long" form with one row descriptor marked as required. The row cell is out of visible area.

If I call [self formValidationErrors] after loading, result is an empty array.
If I scroll down until the required row cell is visible and I call [self formValidationErrors], result is the array with the expected NSError object

XLFormButtonCell selected options

If i have button type cell with no buttonViewController set, should the cell default to formRowDescriptorValueHasChanged?

Right now the behavior is present view controller, but if you like to do something that doesn't require another controller how would i get notified. I've tried to use KVO but no such luck.

Thinking of setting self.rowDescriptor.value = nil if buttonViewController not present, but is that there corrent way forward?

Add a custom row type

I'd like a custom row type added. An object would be provided that could modify the title, provide a textual value for a label or a UIView for the label (given a frame) and then perform an editing operation. Perhaps even validation.

This would obviously allow a developer to implement any type of data input method. You could do an image picker, address picker, etc.

If you are really ambitious, you could implement all existing types as subclasses of this object. I see you have XLFormSwitchCell as a base class, which would be a good start. Then the constants like XLFormRowDescriptorTypeText would just be singletons. Validation would be somewhat easier, since each class could do it's own and users could subclass a text field, say, to do custom validation.

You could, of course, have a list of XLFormValidator objects that are passed to each cell, I guess. You'd need types like XLFormRowDescriptorTypeText to be properties that returned a new instance, then, so the user could easily add validators to various cells.

I hope this makes sense. If you are open to this, I'd be open to helping code this solution.

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.