Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Examples/Objective-C/Examples/Inputs/InputsFormViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
NSString *const kUrl = @"url";
NSString *const kTextView = @"textView";
NSString *const kNotes = @"notes";
NSString *const kCCLast4Digits = @"ccLast4Digits";
NSString *const kCCExpiryDate = @"ccExpiryDate";


@implementation InputsFormViewController
Expand Down Expand Up @@ -110,6 +112,18 @@ -(id)init
row = [XLFormRowDescriptor formRowDescriptorWithTag:kNotes rowType:XLFormRowDescriptorTypeTextView title:@"Notes"];
[section addFormRow:row];

// Credit Card additions
section = [XLFormSectionDescriptor formSectionWithTitle:@"Credit Card Example"];
[formDescriptor addFormSection:section];

row = [XLFormRowDescriptor formRowDescriptorWithTag:kCCLast4Digits rowType:XLFormRowDescriptorTypeInteger title:@"Last 4 Digits"];
row.maxLength = 4;
[section addFormRow:row];

row = [XLFormRowDescriptor formRowDescriptorWithTag:kCCExpiryDate rowType:XLFormRowDescriptorTypeCreditCardExpiryDate title:@"Expiry Date"];
[row.cellConfigAtConfigure setObject:@"MM/YY" forKey:@"textField.placeholder"];
[section addFormRow:row];

return [super initWithForm:formDescriptor];

}
Expand Down
41 changes: 41 additions & 0 deletions XLForm/XL/Cell/XLFormTextFieldCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ -(void)update
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
}
else if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeCreditCardExpiryDate]){
self.textField.keyboardType = UIKeyboardTypeNumberPad;
self.textField.autocorrectionType = UITextAutocorrectionTypeNo;
self.textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
self.rowDescriptor.maxLength = 5;
}

self.textLabel.text = ((self.rowDescriptor.required && self.rowDescriptor.title && self.rowDescriptor.sectionDescriptor.formDescriptor.addAsteriskToRequiredRowsTitle) ? [NSString stringWithFormat:@"%@*", self.rowDescriptor.title] : self.rowDescriptor.title);

Expand Down Expand Up @@ -240,6 +246,18 @@ - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

if (self.rowDescriptor.maxLength > 0) {
// Prevent crashing undo bug – see note below.
if (range.length + range.location > textField.text.length)
{
return NO;
}

NSUInteger newLength = [textField.text length] + [string length] - range.length;
return (newLength < self.rowDescriptor.maxLength + 1) ? YES : NO;
}

return [self.formViewController textField:textField shouldChangeCharactersInRange:range replacementString:string];
}

Expand All @@ -256,6 +274,22 @@ - (void)textFieldDidEndEditing:(UITextField *)textField
[self.formViewController textFieldDidEndEditing:textField];
}

- (NSString *)formatCreditCardExpiry:(NSString *)text
{
static NSString *previousText = @"";

if (text.length == 2) {
if (previousText.length < text.length) {
text = [NSString stringWithFormat:@"%@/", text];
} else {
text = [text substringToIndex:1];
}
}

previousText = text;

return text;
}

#pragma mark - Helper

Expand All @@ -271,6 +305,13 @@ - (void)textFieldDidChange:(UITextField *)textField{
} else {
self.rowDescriptor.value = nil;
}

if ([self.rowDescriptor.rowType isEqualToString:XLFormRowDescriptorTypeCreditCardExpiryDate]) {
NSString *formattedText = [self formatCreditCardExpiry:self.textField.text];
if (![formattedText isEqualToString:self.textField.text]) {
self.textField.text = formattedText;
}
}
}

-(void)setReturnKeyType:(UIReturnKeyType)returnKeyType
Expand Down
3 changes: 2 additions & 1 deletion XLForm/XL/Controllers/XLFormViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ +(NSMutableDictionary *)cellClassesForRowDescriptorTypes
XLFormRowDescriptorTypePicker : [XLFormPickerCell class],
XLFormRowDescriptorTypeSlider : [XLFormSliderCell class],
XLFormRowDescriptorTypeSelectorLeftRight : [XLFormLeftRightSelectorCell class],
XLFormRowDescriptorTypeStepCounter: [XLFormStepCounterCell class]
XLFormRowDescriptorTypeStepCounter: [XLFormStepCounterCell class],
XLFormRowDescriptorTypeCreditCardExpiryDate: [XLFormTextFieldCell class]
} mutableCopy];
});
return _cellClassesForRowDescriptorTypes;
Expand Down
4 changes: 2 additions & 2 deletions XLForm/XL/Descriptors/XLFormDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ -(instancetype)initWithTitle:(NSString *)title;

+(instancetype)formDescriptor
{
return [[self class] formDescriptorWithTitle:nil];
return [self formDescriptorWithTitle:nil];
}

+(instancetype)formDescriptorWithTitle:(NSString *)title
{
return [[[self class] alloc] initWithTitle:title];
return [[XLFormDescriptor alloc] initWithTitle:title];
}

-(void)addFormSection:(XLFormSectionDescriptor *)formSection
Expand Down
2 changes: 2 additions & 0 deletions XLForm/XL/Descriptors/XLFormRowDescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ typedef NS_ENUM(NSUInteger, XLFormPresentationMode) {
@property (nonatomic) id value;
@property Class valueTransformer;
@property UITableViewCellStyle cellStyle;
@property int maxLength;

@property (nonatomic) NSMutableDictionary *cellConfig;
@property (nonatomic) NSMutableDictionary *cellConfigIfDisabled;
Expand Down Expand Up @@ -141,3 +142,4 @@ typedef NS_ENUM(NSUInteger, XLFormPresentationMode) {
@property (nonatomic, strong) Class formSegueClass;

@end

6 changes: 4 additions & 2 deletions XLForm/XL/Descriptors/XLFormRowDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ -(instancetype)initWithTag:(NSString *)tag rowType:(NSString *)rowType title:(NS
_rowType = rowType;
_title = title;
_cellStyle = UITableViewCellStyleValue1;
_maxLength = 0;
_validators = [NSMutableArray new];
_cellConfig = [NSMutableDictionary dictionary];
_cellConfigIfDisabled = [NSMutableDictionary dictionary];
Expand All @@ -98,12 +99,12 @@ -(instancetype)initWithTag:(NSString *)tag rowType:(NSString *)rowType title:(NS

+(instancetype)formRowDescriptorWithTag:(NSString *)tag rowType:(NSString *)rowType
{
return [[self class] formRowDescriptorWithTag:tag rowType:rowType title:nil];
return [XLFormRowDescriptor formRowDescriptorWithTag:tag rowType:rowType title:nil];
}

+(instancetype)formRowDescriptorWithTag:(NSString *)tag rowType:(NSString *)rowType title:(NSString *)title
{
return [[[self class] alloc] initWithTag:tag rowType:rowType title:title];
return [[XLFormRowDescriptor alloc] initWithTag:tag rowType:rowType title:title];
}

-(XLFormBaseCell *)cellForFormController:(XLFormViewController *)formController
Expand Down Expand Up @@ -590,3 +591,4 @@ -(void)setFormSegueIdenfifier:(NSString *)formSegueIdenfifier
}

@end

10 changes: 5 additions & 5 deletions XLForm/XL/Descriptors/XLFormSectionDescriptor.m
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,27 @@ -(instancetype)initWithTitle:(NSString *)title sectionOptions:(XLFormSectionOpti

+(instancetype)formSection
{
return [[self class] formSectionWithTitle:nil];
return [self formSectionWithTitle:nil];
}

+(instancetype)formSectionWithTitle:(NSString *)title
{
return [[self class] formSectionWithTitle:title sectionOptions:XLFormSectionOptionNone];
return [self formSectionWithTitle:title sectionOptions:XLFormSectionOptionNone];
}

+(instancetype)formSectionWithTitle:(NSString *)title multivaluedSection:(BOOL)multivaluedSection
{
return [[self class] formSectionWithTitle:title sectionOptions:(multivaluedSection ? XLFormSectionOptionCanInsert | XLFormSectionOptionCanDelete : XLFormSectionOptionNone)];
return [self formSectionWithTitle:title sectionOptions:(multivaluedSection ? XLFormSectionOptionCanInsert | XLFormSectionOptionCanDelete : XLFormSectionOptionNone)];
}

+(instancetype)formSectionWithTitle:(NSString *)title sectionOptions:(XLFormSectionOptions)sectionOptions
{
return [[self class] formSectionWithTitle:title sectionOptions:sectionOptions sectionInsertMode:XLFormSectionInsertModeLastRow];
return [self formSectionWithTitle:title sectionOptions:sectionOptions sectionInsertMode:XLFormSectionInsertModeLastRow];
}

+(instancetype)formSectionWithTitle:(NSString *)title sectionOptions:(XLFormSectionOptions)sectionOptions sectionInsertMode:(XLFormSectionInsertMode)sectionInsertMode
{
return [[[self class] alloc] initWithTitle:title sectionOptions:sectionOptions sectionInsertMode:sectionInsertMode];
return [[XLFormSectionDescriptor alloc] initWithTitle:title sectionOptions:sectionOptions sectionInsertMode:sectionInsertMode];
}

-(BOOL)isMultivaluedSection
Expand Down
1 change: 1 addition & 0 deletions XLForm/XL/XLForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ extern NSString *const XLFormRowDescriptorTypeBooleanSwitch;
extern NSString *const XLFormRowDescriptorTypeButton;
extern NSString *const XLFormRowDescriptorTypeInfo;
extern NSString *const XLFormRowDescriptorTypeStepCounter;
extern NSString *const XLFormRowDescriptorTypeCreditCardExpiryDate;


#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
Expand Down
2 changes: 1 addition & 1 deletion XLForm/XL/XLForm.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,4 @@
NSString *const XLFormRowDescriptorTypeButton = @"button";
NSString *const XLFormRowDescriptorTypeInfo = @"info";
NSString *const XLFormRowDescriptorTypeStepCounter = @"stepCounter";

NSString *const XLFormRowDescriptorTypeCreditCardExpiryDate = @"expiry";