7 Commits

Author SHA1 Message Date
Mathias Claassen e9de49db86 formValuesIncludingHidden returns all values of a form including the values of hidden rows 2017-05-18 11:56:26 -03:00
MiMo42 77db6b9492 nullability warning fixed (#952) 2017-04-26 10:21:35 -03:00
Mathias Claassen 74b26c1e64 make properties of XLFormOptionsObject writable (#955) 2017-04-25 11:55:54 -03:00
Mathias Claassen 085cf31e52 Updated Readme Eureka introduction (#954) 2017-04-25 10:48:47 -03:00
FatalDizz 313e5d5d40 Added method to set a title for form errors (#951) 2017-04-19 11:46:34 -03:00
Mathias Claassen f7777d9d27 Add Header and Footer section to Readme FAQ (#942) 2017-04-05 09:46:52 -03:00
Mathias Claassen 578dea99dd Use the correct locale in date row (not only date picker) (#935) 2017-04-05 09:23:41 -03:00
11 changed files with 102 additions and 14 deletions
@@ -57,6 +57,7 @@ NSString *const kCountDownTimer = @"countDownTimer";
// Date
row = [XLFormRowDescriptor formRowDescriptorWithTag:kDateInline rowType:XLFormRowDescriptorTypeDateInline title:@"Date"];
row.value = [NSDate new];
[row.cellConfigAtConfigure setObject:[NSLocale localeWithLocaleIdentifier:@"FR_fr" ] forKey:@"locale"];
[section addFormRow:row];
// Time
@@ -76,6 +76,7 @@ class DatesFormViewController: XLFormViewController {
// Date
row = XLFormRowDescriptor(tag: Tags.DateInline, rowType: XLFormRowDescriptorTypeDateInline, title:"Date")
row.value = Date()
row.cellConfigAtConfigure["locale"] = Locale(identifier: "FR_fr")
section.addFormRow(row)
// Time
+20 -1
View File
@@ -6,7 +6,7 @@ By [XMARTLABS](http://xmartlabs.com).
[![Build Status](https://travis-ci.org/xmartlabs/XLForm.svg?branch=master)](https://travis-ci.org/xmartlabs/XLForm)
<a href="https://cocoapods.org/pods/XLForm"><img src="https://img.shields.io/cocoapods/v/XLForm.svg" alt="CocoaPods compatible" /></a>
**If you are looking for Swift native implementation we have recently created [Eureka], a complete re-design of XLForm in Swift.** *Do not panic, We will continue maintaining and improving XLForm, obj-c rocks!!*
**If you are working in Swift then you should have a look at [Eureka], a complete re-design of XLForm in Swift.** *Do not panic, we will continue maintaining and improving XLForm, obj-c rocks!!*
Purpose
--------------
@@ -897,6 +897,25 @@ 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:
```objc
-(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:
```objc
-(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`.
+16 -3
View File
@@ -37,6 +37,7 @@
@implementation XLFormDateCell
{
UIColor * _beforeChangeColor;
NSDateFormatter *_dateFormatter;
}
@@ -109,6 +110,7 @@
{
[super configure];
self.formDatePickerMode = XLFormDateDatePickerModeGetFromRowDescriptor;
_dateFormatter = [[NSDateFormatter alloc] init];
}
-(void)update
@@ -173,10 +175,14 @@
}
}
if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeDate] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeDateInline]){
return [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterMediumStyle timeStyle:NSDateFormatterNoStyle];
_dateFormatter.dateStyle = NSDateFormatterMediumStyle;
_dateFormatter.timeStyle = NSDateFormatterNoStyle;
return [_dateFormatter stringFromDate:date];
}
else if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTime] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeTimeInline]){
return [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterNoStyle timeStyle:NSDateFormatterShortStyle];
_dateFormatter.dateStyle = NSDateFormatterNoStyle;
_dateFormatter.timeStyle = NSDateFormatterShortStyle;
return [_dateFormatter stringFromDate:date];
}
else if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeCountDownTimer] || [self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeCountDownTimerInline]){
NSCalendar *calendar = [NSCalendar currentCalendar];
@@ -184,7 +190,9 @@
NSDateComponents *time = [calendar components:NSCalendarUnitHour | NSCalendarUnitMinute fromDate:date];
return [NSString stringWithFormat:@"%ld%@ %ldmin", (long)[time hour], (long)[time hour] == 1 ? @"hour" : @"hours", (long)[time minute]];
}
return [NSDateFormatter localizedStringFromDate:date dateStyle:NSDateFormatterShortStyle timeStyle:NSDateFormatterShortStyle];
_dateFormatter.dateStyle = NSDateFormatterShortStyle;
_dateFormatter.timeStyle = NSDateFormatterShortStyle;
return [_dateFormatter stringFromDate:date];
}
-(void)setModeToDatePicker:(UIDatePicker *)datePicker
@@ -228,6 +236,11 @@
return _datePicker;
}
-(void)setLocale:(NSLocale *)locale
{
_locale = locale;
_dateFormatter.locale = locale;
}
#pragma mark - Target Action
@@ -28,6 +28,9 @@
@interface XLFormOptionsObject : NSObject <XLFormOptionObject,NSCoding>
@property (nonatomic) NSString * formDisplaytext;
@property (nonatomic) id formValue;
+(XLFormOptionsObject *)formOptionsObjectWithValue:(id)value displayText:(NSString *)displayText;
+(XLFormOptionsObject *)formOptionsOptionForValue:(id)value fromOptions:(NSArray *)options;
+(XLFormOptionsObject *)formOptionsOptionForDisplayText:(NSString *)displayText fromOptions:(NSArray *)options;
+3 -4
View File
@@ -26,10 +26,6 @@
#import "XLFormOptionsObject.h"
@implementation XLFormOptionsObject
{
NSString * _formDisplaytext;
id _formValue;
}
+(XLFormOptionsObject *)formOptionsObjectWithValue:(id)value displayText:(NSString *)displayText
{
@@ -85,6 +81,7 @@
{
return _formValue;
}
#pragma mark - NSCoding
-(void)encodeWithCoder:(NSCoder *)encoder
{
@@ -94,6 +91,7 @@
[encoder encodeObject:self.formDisplayText
forKey:@"formDisplayText"];
}
-(instancetype)initWithCoder:(NSCoder *)decoder
{
if ((self=[super init])) {
@@ -108,4 +106,5 @@
return self;
}
@end
@@ -52,6 +52,7 @@ typedef NS_ENUM(NSUInteger, XLFormRowNavigationDirection) {
-(XLFormBaseCell *)updateFormRow:(XLFormRowDescriptor *)formRow;
-(NSDictionary *)formValues;
-(NSDictionary *)formValuesIncludingHidden;
-(NSDictionary *)httpParameters;
-(XLFormRowDescriptor *)formRowFormMultivaluedFormSection:(XLFormSectionDescriptor *)formSection;
@@ -60,6 +61,7 @@ typedef NS_ENUM(NSUInteger, XLFormRowNavigationDirection) {
-(NSArray *)formValidationErrors;
-(void)showFormValidationError:(NSError *)error;
-(void)showFormValidationError:(NSError *)error withTitle:(NSString*)title;
-(UITableViewRowAnimation)insertRowAnimationForRow:(XLFormRowDescriptor *)formRow;
-(UITableViewRowAnimation)deleteRowAnimationForRow:(XLFormRowDescriptor *)formRow;
@@ -346,6 +346,11 @@
return [self.form formValues];
}
-(NSDictionary *)formValuesIncludingHidden
{
return [self.form formValuesIncludingHidden];
}
-(NSDictionary *)httpParameters
{
return [self.form httpParameters:self];
@@ -492,6 +497,38 @@
#endif
}
-(void)showFormValidationError:(NSError *)error withTitle:(NSString*)title
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED < 80000
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(title, nil)
message:error.localizedDescription
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil];
[alertView show];
#else
if ([UIAlertController class]){
UIAlertController * alertController = [UIAlertController alertControllerWithTitle:NSLocalizedString(title, nil)
message:error.localizedDescription
preferredStyle:UIAlertControllerStyleAlert];
[alertController addAction:[UIAlertAction actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:nil]];
[self presentViewController:alertController animated:YES completion:nil];
}
#ifndef XL_APP_EXTENSIONS
else{
UIAlertView * alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(title, nil)
message:error.localizedDescription
delegate:self
cancelButtonTitle:NSLocalizedString(@"OK", nil)
otherButtonTitles:nil];
[alertView show];
}
#endif
#endif
}
-(void)performFormSelector:(SEL)selector withObject:(id)sender
{
UIResponder * responder = [self targetForAction:selector withSender:sender];;
+1
View File
@@ -82,6 +82,7 @@ typedef NS_OPTIONS(NSUInteger, XLFormRowNavigationOptions) {
-(nullable NSIndexPath *)indexPathOfFormRow:(nonnull XLFormRowDescriptor *)formRow;
-(nonnull NSDictionary *)formValues;
-(nonnull NSDictionary *)formValuesIncludingHidden;
-(nonnull NSDictionary *)httpParameters:(nonnull XLFormViewController *)formViewController;
-(nonnull NSArray *)localValidationErrors:(nonnull XLFormViewController *)formViewController;
+17 -5
View File
@@ -284,13 +284,25 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
return nil;
}
-(NSDictionary *)formValuesIncludingHidden
{
return [self formValuesWithHidden:YES];
}
-(NSDictionary *)formValues
{
NSMutableDictionary * result = [NSMutableDictionary dictionary];
for (XLFormSectionDescriptor * section in self.formSections) {
return [self formValuesWithHidden:NO];
}
-(NSDictionary *)formValuesWithHidden:(BOOL)includeHidden
{
NSArray* sections = includeHidden ? self.allSections : self.formSections;
NSMutableDictionary* result = [NSMutableDictionary dictionary];
for (XLFormSectionDescriptor * section in sections) {
NSArray* rows = includeHidden ? section.allRows : section.formRows;
if (section.multivaluedTag.length > 0){
NSMutableArray * multiValuedValuesArray = [NSMutableArray new];
for (XLFormRowDescriptor * row in section.formRows) {
NSMutableArray* multiValuedValuesArray = [NSMutableArray new];
for (XLFormRowDescriptor * row in rows) {
if (row.value){
[multiValuedValuesArray addObject:row.value];
}
@@ -298,7 +310,7 @@ NSString * const XLValidationStatusErrorKey = @"XLValidationStatusErrorKey";
[result setObject:multiValuedValuesArray forKey:section.multivaluedTag];
}
else{
for (XLFormRowDescriptor * row in section.formRows) {
for (XLFormRowDescriptor * row in rows) {
if (row.tag.length > 0){
[result setObject:(row.value ?: [NSNull null]) forKey:row.tag];
}
@@ -69,6 +69,6 @@ typedef NS_ENUM(NSUInteger, XLFormSectionInsertMode) {
-(void)addFormRow:(nonnull XLFormRowDescriptor *)formRow beforeRow:(nonnull XLFormRowDescriptor *)beforeRow;
-(void)removeFormRowAtIndex:(NSUInteger)index;
-(void)removeFormRow:(nonnull XLFormRowDescriptor *)formRow;
- (void)moveRowAtIndexPath:(NSIndexPath *)sourceIndex toIndexPath:(NSIndexPath *)destinationIndex;
-(void)moveRowAtIndexPath:(nonnull NSIndexPath *)sourceIndex toIndexPath:(nonnull NSIndexPath *)destinationIndex;
@end