code review
This commit is contained in:
parent
ff3055a4c7
commit
8b3d561543
@ -31,7 +31,6 @@
|
||||
|
||||
@property (strong, nonatomic) NSMutableArray <MFTextField *>*textFields;
|
||||
@property (nonatomic, readwrite, assign) PrimaryButtonType primaryButtonType;
|
||||
@property (nonnull, strong, nonatomic) FormValidator* formValidator;
|
||||
|
||||
@end
|
||||
|
||||
@ -682,7 +681,6 @@
|
||||
|
||||
- (void)setEnabledByValidity {
|
||||
|
||||
|
||||
__block BOOL valid = YES;
|
||||
[self.textFields enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if (!((MFTextField *)obj).valid) {
|
||||
@ -711,7 +709,7 @@
|
||||
[self setEnabledByValidity];
|
||||
}
|
||||
|
||||
- (void)addTextFieldsForValidation:(nonnull MFTextField *)textField{
|
||||
- (void)addTextFieldsForValidation:(nonnull MFTextField *)textField {
|
||||
if (self.textFields == nil) {
|
||||
self.textFields = [NSMutableArray array];
|
||||
}
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textContainerRightPin;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *errorLableRightPin;
|
||||
@property (nonatomic) BOOL isMolecule;
|
||||
|
||||
@end
|
||||
|
||||
@ -48,6 +49,13 @@
|
||||
self.label.font = [MFStyler fontForTextFieldUnderLabel];
|
||||
[MFStyler styleTextField:self.textField];
|
||||
[self.dashLine updateView:size];
|
||||
|
||||
if (self.isMolecule) {
|
||||
[self setVerticalPadding:[MFStyler defaultHorizontalPaddingForApplicationWidth]];
|
||||
|
||||
} else {
|
||||
[self setVerticalPadding:0];
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
||||
@ -109,17 +117,17 @@
|
||||
}
|
||||
|
||||
- (void)setWithJSON:(NSDictionary *)json delegate:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate additionalData:(NSDictionary *)additionalData {
|
||||
[FormValidator setupValidationWithMolecule:self delegate: (id<FormValidationProtocol>)delegate];
|
||||
|
||||
|
||||
self.isMolecule = YES;
|
||||
[FormValidator setupValidationWithMolecule:self delegate:(id<FormValidationProtocol>)delegate];
|
||||
[self setWithMap:json bothDelegates:delegate];
|
||||
|
||||
FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:(id<FormValidationProtocol>)delegate];
|
||||
self.mfTextFieldDelegate = formValidator;
|
||||
self.uiTextFieldDelegate = formValidator;
|
||||
[self setVerticalPadding:[MFStyler defaultHorizontalPaddingForApplicationWidth]];
|
||||
}
|
||||
|
||||
- (void) setVerticalPadding:(CGFloat) padding {
|
||||
- (void)setVerticalPadding:(CGFloat) padding {
|
||||
self.textContainerLeftPin.constant = padding;
|
||||
self.errorLableLeftPin.constant = padding;
|
||||
self.formLabelLeftPin.constant = padding;
|
||||
@ -134,7 +142,6 @@
|
||||
MFTextField *textField = [self mfTextField];
|
||||
textField.translatesAutoresizingMaskIntoConstraints = NO;
|
||||
[textField setWithJSON:map delegate:delegate additionalData:nil];
|
||||
[textField setVerticalPadding:0];
|
||||
return textField;
|
||||
}
|
||||
|
||||
@ -319,53 +326,55 @@
|
||||
}
|
||||
|
||||
- (void)setWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate {
|
||||
if (map.count > 0) {
|
||||
[MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:delegate];
|
||||
[self setBothTextFieldDelegates:delegate];
|
||||
|
||||
NSString *string = [map string:KeyLabel];
|
||||
if (string.length > 0) {
|
||||
self.formText = string;
|
||||
}
|
||||
string = [map string:KeyValue];
|
||||
if (string.length > 0) {
|
||||
self.text = string;
|
||||
}
|
||||
string = [map stringForKey:KeyDisable];
|
||||
if ([string isEqual:StringY] || [map boolForKey:KeyDisable]) {
|
||||
[self enable:NO];
|
||||
}
|
||||
string = [map string:KeyErrorMessage];
|
||||
if (string.length > 0) {
|
||||
self.errMessage = string;
|
||||
}
|
||||
|
||||
// key used to send text value to server
|
||||
string = [map string:@"fieldKey"];
|
||||
if (string.length > 0) {
|
||||
self.fieldKey = string;
|
||||
}
|
||||
|
||||
string = [map string:KeyType];
|
||||
if ([string isEqualToString:@"dropDown"]) {
|
||||
[[self dropDownCarrotLabel] setHidden:NO];
|
||||
[self setHasDropDown:YES];
|
||||
} else if ([string isEqualToString:@"password"]) {
|
||||
self.textField.secureTextEntry = YES;
|
||||
} else if ([string isEqualToString:@"number"]) {
|
||||
self.textField.keyboardType = UIKeyboardTypeNumberPad;
|
||||
} else if ([string isEqualToString:@"email"]) {
|
||||
self.textField.keyboardType = UIKeyboardTypeEmailAddress;
|
||||
}
|
||||
|
||||
string = [map string:@"regex"];
|
||||
if (string.length) {
|
||||
self.validationBlock = ^BOOL(NSString * _Nullable enteredValue) {
|
||||
return [MVMCoreUIUtility validateString:enteredValue withRegularExpression:string];
|
||||
};
|
||||
} else {
|
||||
[self setDefaultValidationBlock];
|
||||
}
|
||||
if (map.count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
[MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:delegate];
|
||||
[self setBothTextFieldDelegates:delegate];
|
||||
|
||||
NSString *string = [map string:KeyLabel];
|
||||
if (string.length > 0) {
|
||||
self.formText = string;
|
||||
}
|
||||
string = [map string:KeyValue];
|
||||
if (string.length > 0) {
|
||||
self.text = string;
|
||||
}
|
||||
string = [map stringForKey:KeyDisable];
|
||||
if ([string isEqual:StringY] || [map boolForKey:KeyDisable]) {
|
||||
[self enable:NO];
|
||||
}
|
||||
string = [map string:KeyErrorMessage];
|
||||
if (string.length > 0) {
|
||||
self.errMessage = string;
|
||||
}
|
||||
|
||||
// key used to send text value to server
|
||||
string = [map string:@"fieldKey"];
|
||||
if (string.length > 0) {
|
||||
self.fieldKey = string;
|
||||
}
|
||||
|
||||
string = [map string:KeyType];
|
||||
if ([string isEqualToString:@"dropDown"]) {
|
||||
[[self dropDownCarrotLabel] setHidden:NO];
|
||||
[self setHasDropDown:YES];
|
||||
} else if ([string isEqualToString:@"password"]) {
|
||||
self.textField.secureTextEntry = YES;
|
||||
} else if ([string isEqualToString:@"number"]) {
|
||||
self.textField.keyboardType = UIKeyboardTypeNumberPad;
|
||||
} else if ([string isEqualToString:@"email"]) {
|
||||
self.textField.keyboardType = UIKeyboardTypeEmailAddress;
|
||||
}
|
||||
|
||||
string = [map string:@"regex"];
|
||||
if (string.length) {
|
||||
self.validationBlock = ^BOOL(NSString * _Nullable enteredValue) {
|
||||
return [MVMCoreUIUtility validateString:enteredValue withRegularExpression:string];
|
||||
};
|
||||
} else {
|
||||
[self setDefaultValidationBlock];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user