molecule testfields

This commit is contained in:
Suresh, Kamlesh 2019-03-26 13:51:33 -04:00
parent 7920f8f550
commit 69309cf3b1
20 changed files with 521 additions and 83 deletions

View File

@ -7,8 +7,16 @@
objects = {
/* Begin PBXBuildFile section */
01174B912243E54200A8FE68 /* MVMCoreUIFormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01174B902243E54200A8FE68 /* MVMCoreUIFormValidator+TextFields.swift */; };
01BDA2D522442E6B001DACC9 /* MVMCoreUIFormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01BDA2D422442E6B001DACC9 /* MVMCoreUIFormValidator+FormParams.swift */; };
01BDA2D722442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 01BDA2D622442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h */; };
01C0B24A224A9C2000F89DF2 /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C0B249224A9C2000F89DF2 /* FormValidator.swift */; };
01C74D8C22429978009C25A3 /* MVMCoreUIFormValidator.h in Headers */ = {isa = PBXBuildFile; fileRef = 01C74D8A22429978009C25A3 /* MVMCoreUIFormValidator.h */; settings = {ATTRIBUTES = (Public, ); }; };
01C74D8D22429978009C25A3 /* MVMCoreUIFormValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = 01C74D8B22429978009C25A3 /* MVMCoreUIFormValidator.m */; };
01C74D8F22429A0F009C25A3 /* MVMCoreUIFormValidationProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 01C74D8E22429A0F009C25A3 /* MVMCoreUIFormValidationProtocol.h */; settings = {ATTRIBUTES = (Public, ); }; };
01DF55E021F8FAA800CC099B /* MFTextFieldListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */; };
01DF567021FA5AB300CC099B /* TextFieldListFormViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */; };
01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */ = {isa = PBXBuildFile; fileRef = D2A5146A2214905000345BFB /* ThreeLayerViewController.swift */; settings = {ATTRIBUTES = (Public, ); }; };
D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationController.h in Headers */ = {isa = PBXBuildFile; fileRef = D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */; settings = {ATTRIBUTES = (Public, ); }; };
D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationController.m in Sources */ = {isa = PBXBuildFile; fileRef = D206997621FB8A0B00CAE0DE /* MVMCoreUINavigationController.m */; };
D22D1F1A220341F60077CEC0 /* MVMCoreUICheckBox.h in Headers */ = {isa = PBXBuildFile; fileRef = D22D1F18220341F50077CEC0 /* MVMCoreUICheckBox.h */; settings = {ATTRIBUTES = (Public, ); }; };
@ -161,6 +169,13 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
01174B902243E54200A8FE68 /* MVMCoreUIFormValidator+TextFields.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUIFormValidator+TextFields.swift"; sourceTree = "<group>"; };
01BDA2D422442E6B001DACC9 /* MVMCoreUIFormValidator+FormParams.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "MVMCoreUIFormValidator+FormParams.swift"; sourceTree = "<group>"; };
01BDA2D622442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIFormMoleculesProtocol.h; sourceTree = "<group>"; };
01C0B249224A9C2000F89DF2 /* FormValidator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = "<group>"; };
01C74D8A22429978009C25A3 /* MVMCoreUIFormValidator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIFormValidator.h; sourceTree = "<group>"; };
01C74D8B22429978009C25A3 /* MVMCoreUIFormValidator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = MVMCoreUIFormValidator.m; sourceTree = "<group>"; };
01C74D8E22429A0F009C25A3 /* MVMCoreUIFormValidationProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIFormValidationProtocol.h; sourceTree = "<group>"; };
01DF55DF21F8FAA800CC099B /* MFTextFieldListView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MFTextFieldListView.swift; sourceTree = "<group>"; };
01DF566F21FA5AB300CC099B /* TextFieldListFormViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TextFieldListFormViewController.swift; sourceTree = "<group>"; };
D206997521FB8A0B00CAE0DE /* MVMCoreUINavigationController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUINavigationController.h; sourceTree = "<group>"; };
@ -331,6 +346,27 @@
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
01C74D86224298C3009C25A3 /* Protocols */ = {
isa = PBXGroup;
children = (
01C74D8E22429A0F009C25A3 /* MVMCoreUIFormValidationProtocol.h */,
01BDA2D622442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h */,
);
path = Protocols;
sourceTree = "<group>";
};
01C74D87224298E2009C25A3 /* Models */ = {
isa = PBXGroup;
children = (
01C0B249224A9C2000F89DF2 /* FormValidator.swift */,
01C74D8A22429978009C25A3 /* MVMCoreUIFormValidator.h */,
01C74D8B22429978009C25A3 /* MVMCoreUIFormValidator.m */,
01174B902243E54200A8FE68 /* MVMCoreUIFormValidator+TextFields.swift */,
01BDA2D422442E6B001DACC9 /* MVMCoreUIFormValidator+FormParams.swift */,
);
path = Models;
sourceTree = "<group>";
};
D22D1F582204D2590077CEC0 /* LegacyControllers */ = {
isa = PBXGroup;
children = (
@ -364,6 +400,8 @@
D29DF0CE21E404D4003B2FB9 /* MVMCoreUI */ = {
isa = PBXGroup;
children = (
01C74D87224298E2009C25A3 /* Models */,
01C74D86224298C3009C25A3 /* Protocols */,
D29DF31421ECECA7003B2FB9 /* SupportingFiles */,
D29DF27021E79B2C003B2FB9 /* OtherHandlers */,
D29DF13A21E68682003B2FB9 /* Utility */,
@ -701,6 +739,7 @@
D29DF27921E7A533003B2FB9 /* MVMCoreUISession.h in Headers */,
D29DF25C21E6A2B6003B2FB9 /* DashLine.h in Headers */,
D206997721FB8A0B00CAE0DE /* MVMCoreUINavigationController.h in Headers */,
01C74D8C22429978009C25A3 /* MVMCoreUIFormValidator.h in Headers */,
D29DF29D21E7AE38003B2FB9 /* MFStyler.h in Headers */,
D29DF2B021E7B3A4003B2FB9 /* MFTextView.h in Headers */,
D29DF2A921E7B2F9003B2FB9 /* MVMCoreUIConstants.h in Headers */,
@ -740,6 +779,7 @@
D2C5001D21F8EE67001DA659 /* LabelWithInternalButton.h in Headers */,
D29DF11621E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.h in Headers */,
D29DF17721E69E1F003B2FB9 /* MFTextButton.h in Headers */,
01E569D3223FFFA500327251 /* ThreeLayerViewController.swift in Headers */,
D29DF16221E69996003B2FB9 /* MFViewController.h in Headers */,
D29DF13121E6851E003B2FB9 /* MVMCoreUITopAlertExpandableView.h in Headers */,
D29DF2C421E7BF57003B2FB9 /* MFTabBarSwipeAnimator.h in Headers */,
@ -755,9 +795,11 @@
D29770F321F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.h in Headers */,
D2C5001821F8ECDD001DA659 /* MVMCoreUIViewControllerMappingObject.h in Headers */,
D29770FD21F7C77400B2F0D0 /* MVMCoreUITextFieldView.h in Headers */,
01BDA2D722442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h in Headers */,
D29DF17421E69E1F003B2FB9 /* MFCustomButton.h in Headers */,
D29DF29721E7ADB8003B2FB9 /* MFScrollingViewController.h in Headers */,
D29DF26F21E6AA0B003B2FB9 /* FLAnimatedImageView.h in Headers */,
01C74D8F22429A0F009C25A3 /* MVMCoreUIFormValidationProtocol.h in Headers */,
D29DF2A121E7AF4E003B2FB9 /* MVMCoreUIUtility.h in Headers */,
D29DF17621E69E1F003B2FB9 /* PrimaryButton.h in Headers */,
D29DF2C821E7BFC1003B2FB9 /* MFSizeObject.h in Headers */,
@ -850,6 +892,7 @@
files = (
D29DF32121ED0CBA003B2FB9 /* LabelView.m in Sources */,
D29770F221F7C6D600B2F0D0 /* TopLabelsAndBottomButtonsTableViewController.m in Sources */,
01BDA2D522442E6B001DACC9 /* MVMCoreUIFormValidator+FormParams.swift in Sources */,
D29DF29621E7ADB8003B2FB9 /* StackableViewController.m in Sources */,
D22D1F1F220343560077CEC0 /* MVMCoreUICheckMarkView.m in Sources */,
D282AAB4223FDDAE00C46919 /* MFLoadImageView.swift in Sources */,
@ -884,6 +927,7 @@
D274CA332236A78900B01B62 /* StandardFooterView.swift in Sources */,
D29DF2BF21E7BEA4003B2FB9 /* MVMCoreUITabBarPageControlViewController.m in Sources */,
D29DF28321E7AB24003B2FB9 /* MVMCoreUICommonViewsUtility.m in Sources */,
01C74D8D22429978009C25A3 /* MVMCoreUIFormValidator.m in Sources */,
D29DF28A21E7AC2B003B2FB9 /* MFLabel.m in Sources */,
D206997821FB8A0B00CAE0DE /* MVMCoreUINavigationController.m in Sources */,
D29DF27A21E7A533003B2FB9 /* MVMCoreUISession.m in Sources */,
@ -906,10 +950,12 @@
D29DF17821E69E1F003B2FB9 /* MFCaretButton.m in Sources */,
D29DF11821E6805F003B2FB9 /* NSLayoutConstraint+MFConvenience.m in Sources */,
D29DF26C21E6AA0B003B2FB9 /* FLAnimatedImage.m in Sources */,
01C0B24A224A9C2000F89DF2 /* FormValidator.swift in Sources */,
D29770FC21F7C77400B2F0D0 /* MVMCoreUITextFieldView.m in Sources */,
D29DF25121E6A177003B2FB9 /* MFDigitTextBox.m in Sources */,
D29DF13221E6851E003B2FB9 /* MVMCoreUITopAlertBaseView.m in Sources */,
D2C5001E21F8EE67001DA659 /* LabelWithInternalButton.m in Sources */,
01174B912243E54200A8FE68 /* MVMCoreUIFormValidator+TextFields.swift in Sources */,
D29DF29C21E7ADB9003B2FB9 /* MFProgrammaticTableViewController.m in Sources */,
D29DF2BE21E7BEA4003B2FB9 /* TopTabbar.m in Sources */,
D2A514632213643100345BFB /* MoleculeStackCenteredTemplate.swift in Sources */,

View File

@ -11,6 +11,7 @@
#import <MVMCoreUI/MFTextField.h>
#import <MVMCoreUI/MFView.h>
#import <MVMCoreUI/MVMCoreUIMoleculeViewProtocol.h>
#import "MVMCoreUIFormValidationProtocol.h"
typedef enum : NSUInteger {
PrimaryButtonTypeRed,
@ -26,7 +27,7 @@ typedef enum : NSUInteger {
static CGFloat const PrimaryButtonHeight = 42.0;
static CGFloat const PrimaryButtonSmallHeight = 30.0;
@interface PrimaryButton : MFCustomButton <MFTextFieldDelegate, UITextFieldDelegate, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol>
@interface PrimaryButton : MFCustomButton <MFTextFieldDelegate, UITextFieldDelegate, MVMCoreViewProtocol, MVMCoreUIMoleculeViewProtocol, MVMCoreUIFormValidationProtocol>
@property (nonatomic, readonly, assign) PrimaryButtonType primaryButtonType; //use reset function to set

View File

@ -12,23 +12,26 @@
#import "MVMCoreUISplitViewController.h"
#import "MFStyler.h"
#import "UIColor+MFConvenience.h"
#import "MVMCoreUIFormValidator.h"
@import MVMCore.MVMCoreDispatchUtility;
@import MVMCore.MVMCoreGetterUtility;
@import MVMCore.NSDictionary_MFConvenience;
@interface PrimaryButton ()
@interface PrimaryButton()
@property (nonatomic) BOOL validationRequired;
@property (nonatomic) BOOL smallButton;
@property (assign, nonatomic) BOOL tinyButton;
@property (nonatomic) CGFloat sizeForSizing;
@property (weak, nonatomic) NSLayoutConstraint *height;
@property (weak, nonatomic) NSLayoutConstraint *width;
@property (strong, nonatomic) NSArray <MFTextField *>*textFields;
@property (strong, nonatomic) NSMutableArray <MFTextField *>*textFields;
@property (nonatomic, readwrite, assign) PrimaryButtonType primaryButtonType;
@property (nonatomic) CGFloat sizeForSizing;
@property (strong, nonatomic) MVMCoreUIFormValidator* formValidator;
@end
@ -645,6 +648,9 @@
}
- (void)setWithJSON:(NSDictionary *)json delegate:(NSObject *)delegate additionalData:(nullable NSDictionary *)additionalData {
[MVMCoreUIFormValidator setupValidationFor:self delegate:delegate];
self.primaryButtonType = PrimaryButtonTypeCustom;
NSString *color = [json string:@"fillColor"];
if (color) {
@ -666,6 +672,8 @@
if ((color = [json string:@"disabledBorderColor"])) {
self.disabledBorderColor = [UIColor mfGetColorForHex:color];
}
self.validationRequired = [json boolForKey:@"validationRequired"];
[self setAsSmallButton:[json boolForKey:@"small"]];
[self setWithActionMap:json actionDelegate:([delegate conformsToProtocol:@protocol(MVMCoreActionDelegateProtocol)] ? (NSObject <MVMCoreActionDelegateProtocol>*)delegate : nil) additionalData:additionalData buttonDelegate:([delegate conformsToProtocol:@protocol(ButtonDelegateProtocol)] ? (id <ButtonDelegateProtocol>)delegate : nil)];
}
@ -673,6 +681,8 @@
#pragma mark - Handling Validations
- (void)setEnabledByValidity {
__block BOOL valid = YES;
[self.textFields enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (!((MFTextField *)obj).valid) {
@ -680,7 +690,7 @@
*stop = YES;
}
}];
[MVMCoreDispatchUtility performBlockOnMainThread:^{
self.enabled = valid && (self.extraValidationBlock ? self.extraValidationBlock() : YES);
}];
@ -692,7 +702,22 @@
field.mfTextFieldDelegate = nil;
}
}
self.textFields = textFields;
self.textFields = [textFields mutableCopy];
for (MFTextField *field in self.textFields) {
field.mfTextFieldDelegate = self;
[field setDefaultValidationBlock];
}
[self setEnabledByValidity];
}
- (void)addTextFieldsForValidation:(nonnull MFTextField *)textField{
if (self.textFields == nil) {
self.textFields = [NSMutableArray array];
}
if (textField) {
[self.textFields addObject:textField];
}
for (MFTextField *field in self.textFields) {
field.mfTextFieldDelegate = self;
@ -708,7 +733,7 @@
field.mfTextFieldDelegate = nil;
}
}
self.textFields = textFields;
self.textFields = [textFields mutableCopy];
for (MFTextField *field in self.textFields) {
field.mfTextFieldDelegate = self;
@ -733,4 +758,23 @@
}
}
#pragma mark - MVMCoreUIFormValidationProtocol
- (nullable MVMCoreUIFormValidator *) formValidatorModel {
return self.formValidator;
}
- (void)setFormValidationModel:(nonnull MVMCoreUIFormValidator *) formValidatorModel {
self.formValidator = formValidatorModel;
}
- (void)enableField:(BOOL) enable {
if (self.validationRequired == NO) {
self.enabled = YES;
} else {
self.enabled = enable;
}
}
@end

View File

@ -8,6 +8,7 @@
#import <UIKit/UIKit.h>
#import <MVMCoreUI/MFView.h>
#import "MVMCoreUIFormValidationProtocol.h"
@class PrimaryButton;
@class MFTextField;
@ -28,7 +29,7 @@
@end
@interface MFTextField : MFView
@interface MFTextField : MFView <MVMCoreUIMoleculeViewProtocol, MVMCoreUIFormValidationProtocol>
@property (nullable, weak, nonatomic) UIView *view;
@ -127,4 +128,7 @@
- (void)setAccessibilityString:(nullable NSString *)accessibilityString;
- (nullable NSString *)formFieldName;
- (nullable id)formFieldValue;
@end

View File

@ -15,17 +15,29 @@
#import "MFLabel.h"
#import "MVMCoreUIUtility.h"
#import "MVMCoreUIConstants.h"
#import "MVMCoreUIFormValidator.h"
#import <MVMCore/MVMCore-Swift.h>
@import MVMCore.MVMCoreDispatchUtility;
@import MVMCore.NSDictionary_MFConvenience;
@import MVMCore.MVMCoreJSONConstants;
@interface MFTextField()
@property (strong, nonatomic) MVMCoreUIFormValidator* formValidator;
@property (strong, nonatomic) UIColor *customPlaceHolderColor;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *separatorHeightConstraint;
@property (strong, nonatomic) UIBezierPath *borderPath;
@property (strong, nonatomic) NSCalendar *calendar;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textContainerLeftPin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *errorLableLeftPin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *formLabelLeftPin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *textContainerRightPin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *errorLableRightPin;
@end
@implementation MFTextField
@ -53,10 +65,7 @@
view.frame = self.frame;
[self addSubview:view];
// self.textFieldContainerView.layer.borderWidth = 1;
// self.textFieldContainerView.layer.borderColor = [UIColor mfSilver].CGColor;
self.textField.font = [MFStyler fontForTextField];
self.translatesAutoresizingMaskIntoConstraints = NO;
self.formLabel.font = [MFStyler fontB3];
@ -101,40 +110,34 @@
return textField;
}
- (void)setWithJSON:(NSDictionary *)json delegate:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate additionalData:(NSDictionary *)additionalData {
[MVMCoreUIFormValidator setupValidationFor:self delegate:delegate];
[self setWithMap:json bothDelegates:delegate];
self.mfTextFieldDelegate = self.formValidator;
self.uiTextFieldDelegate = self.formValidator;
[self setVerticalPadding:[MFStyler defaultHorizontalPaddingForApplicationWidth]];
}
- (void) setVerticalPadding:(CGFloat) padding {
self.textContainerLeftPin.constant = padding;
self.errorLableLeftPin.constant = padding;
self.formLabelLeftPin.constant = padding;
self.textContainerRightPin.constant = padding;
self.errorLableRightPin.constant = padding;
self.formLabelRightPin.constant = padding;
}
+ (nullable instancetype)mfTextFieldWithMap:(nullable NSDictionary *)map bothDelegates:(nullable id<UITextFieldDelegate, MFTextFieldDelegate>)delegate {
MFTextField *textField = [self mfTextField];
textField.translatesAutoresizingMaskIntoConstraints = NO;
[textField setWithMap:map bothDelegates:delegate];
if (map.count > 0) {
// Can add these to the set with map function later after verifying
NSString *string = [map string:@"fieldKey"];
if (string.length > 0) {
textField.fieldKey = string;
}
string = [map string:KeyType];
if ([string isEqualToString:@"dropDown"]) {
[[textField dropDownCarrotLabel] setHidden:NO];
[textField setHasDropDown:YES];
} else if ([string isEqualToString:@"password"]) {
textField.textField.secureTextEntry = YES;
} else if ([string isEqualToString:@"number"]) {
textField.textField.keyboardType = UIKeyboardTypeNumberPad;
} else if ([string isEqualToString:@"email"]) {
textField.textField.keyboardType = UIKeyboardTypeEmailAddress;
}
string = [map string:@"regex"];
if (string.length > 0) {
textField.validationBlock = ^BOOL(NSString * _Nullable enteredValue) {
return [MVMCoreUIUtility validateString:enteredValue withRegularExpression:string];
};
} else {
[textField setDefaultValidationBlock];
}
}
[textField setWithJSON:map delegate:delegate additionalData:nil];
[textField setVerticalPadding:0];
return textField;
}
@ -320,6 +323,9 @@
- (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;
@ -336,8 +342,33 @@
if (string.length > 0) {
self.errMessage = string;
}
[MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:delegate];
[self setBothTextFieldDelegates:delegate];
// 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];
}
}
}
@ -530,4 +561,25 @@
}
}
#pragma mark - MVMCoreUIMoleculeViewProtocol
- (nullable MVMCoreUIFormValidator *) formValidatorModel {
return self.formValidator;
}
- (void)setFormValidationModel:(nonnull MVMCoreUIFormValidator *) formValidatorModel {
self.formValidator = formValidatorModel;
}
- (BOOL) isValidField {
return self.valid;
}
- (nullable NSString *)formFieldName {
return self.fieldKey;
}
- (nullable id)formFieldValue {
return self.text;
}
@end

View File

@ -1,29 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES">
<device id="retina4_7" orientation="portrait">
<adaptation id="fullscreen"/>
</device>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<customFonts key="customFonts">
<array key="HelveticaNeue.ttc">
<string>HelveticaNeue</string>
</array>
</customFonts>
<objects>
<placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="MFTextField">
<connections>
<outlet property="dashLine" destination="hw1-Eo-Szn" id="WCs-FF-LCg"/>
<outlet property="dropDownCarrotLabel" destination="XuL-hz-X9C" id="Kv1-Pd-Kra"/>
<outlet property="dropDownCarrotWidth" destination="DJA-00-1ne" id="SHb-1H-EZD"/>
<outlet property="errorLableLeftPin" destination="8pf-sH-2Ct" id="nhS-H8-RKZ"/>
<outlet property="errorLableRightPin" destination="I5y-Go-vVq" id="TN8-Bi-GEP"/>
<outlet property="formLabel" destination="8zH-YN-qag" id="him-Et-eoN"/>
<outlet property="formLabelLeftPin" destination="gLb-br-rma" id="K1a-jV-qMg"/>
<outlet property="formLabelRightPin" destination="Gkx-Zw-C4C" id="7Nl-BF-Jjo"/>
<outlet property="label" destination="2KH-5l-kKu" id="bld-nC-XdN"/>
<outlet property="separatorHeightConstraint" destination="f1r-3b-nqr" id="Zzz-yD-9zP"/>
<outlet property="separatorView" destination="TDi-WU-Tyf" id="5zT-hU-Myw"/>
<outlet property="textContainerLeftPin" destination="sUf-uc-1Ta" id="k9f-nH-EO3"/>
<outlet property="textContainerRightPin" destination="BkX-rc-bYe" id="wKx-IQ-50w"/>
<outlet property="textField" destination="fQx-7g-t8O" id="FKe-6f-DxN"/>
<outlet property="textFieldContainerView" destination="vFx-S6-fbH" id="85j-fY-e2P"/>
</connections>

View File

@ -36,9 +36,14 @@
#import "MVMCoreUILoggingHandler.h"
#import "MVMCoreUITabBarPageControlViewController.h"
#import "MVMCoreUINavigationController.h"
#import "MVMCoreUIFormValidationProtocol.h"
#import "MVMCoreUIFormValidator.h"
#import <MVMCoreUI/MVMCoreUI-Swift.h>
@import MVMAnimationFramework;
@interface MFViewController ()
@interface MFViewController() <MVMCoreUIFormValidationProtocol>
// A flag for if this view controller is observing for cache updates or not.
@property (nonatomic) BOOL observingForResponseJSONUpdates;
@ -52,10 +57,19 @@
// title view for navigation bar, used for custom navigation titles
@property (weak, nonatomic) UILabel *titleLabel;
@property (strong, nonatomic) MVMCoreUIFormValidator* formValidator;
@end
@implementation MFViewController
- (MVMCoreUIFormValidator *)formValidatorModel {
if (self.formValidator == nil) {
self.formValidator = [MVMCoreUIFormValidator new];
}
return self.formValidator;
}
- (void)dismiss {
if (self.presentingViewController) {
[[MVMCoreNavigationHandler sharedNavigationHandler] dismissViewController:self animated:YES];
@ -241,9 +255,10 @@
if (page) {
self.loadObject.pageJSON = page;
}
[self newDataBuildScreen];
self.needToUpdateUI = YES;
[self updateUI];
// [self newDataBuildScreen];
// self.needToUpdateUI = YES;
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}];
@ -401,11 +416,7 @@
}
// Since we have new data, build stuff for the screen.
[self newDataBuildScreen];
// Update the UI after the view is loaded.
self.needToUpdateUI = YES;
self.needToupdateUIOnScreenSizeChanges = YES;
[self updateUI];
if (UIAccessibilityIsVoiceOverRunning()) {
self.disableAnimations = YES;
@ -416,6 +427,15 @@
}
}
- (void) updateUI {
[self newDataBuildScreen];
[self.formValidator setEnabledByValidity];
// Update the UI after the view is loaded.
self.needToUpdateUI = YES;
self.needToupdateUIOnScreenSizeChanges = YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
@ -587,6 +607,7 @@
[[MVMCoreUISession sharedGlobal].splitViewController.rightPanel willOpenWithActionInformation:actionInformation];
}
[self.formValidator addFormParamsWithRequestParameters:requestParameters];
requestParameters.parentPageType = [self.loadObject.pageJSON stringForKey:@"parentPageType"];
[[MVMCoreLoadHandler sharedGlobal] loadRequest:requestParameters dataForPage:additionalData delegate:self];

View File

@ -10,7 +10,7 @@
import UIKit
import MVMAnimationFramework
public class ThreeLayerViewController: ProgrammaticScrollViewController {
open class ThreeLayerViewController: ProgrammaticScrollViewController {
// The three main views
var topView: UIView?
@ -22,8 +22,8 @@ public class ThreeLayerViewController: ProgrammaticScrollViewController {
private var safeAreaView: UIView?
private var heightConstraint: NSLayoutConstraint?
public override func updateViews() {
open override func updateViews() {
super.updateViews()
let width = view.bounds.width
if let topView = topView as? MVMCoreViewProtocol {
@ -37,7 +37,7 @@ public class ThreeLayerViewController: ProgrammaticScrollViewController {
}
}
public override func updateViewConstraints() {
open override func updateViewConstraints() {
super.updateViewConstraints()
guard let scrollView = scrollView else {
return
@ -50,7 +50,7 @@ public class ThreeLayerViewController: ProgrammaticScrollViewController {
}
}
public override func loadView() {
open override func loadView() {
super.loadView()
// The height is used to keep the bottom view at the bottom.
if let contentView = contentView, let scrollView = scrollView {
@ -59,7 +59,7 @@ public class ThreeLayerViewController: ProgrammaticScrollViewController {
}
}
public override func newDataBuildScreen() {
open override func newDataBuildScreen() {
super.newDataBuildScreen()
// Removes the views
@ -78,27 +78,27 @@ public class ThreeLayerViewController: ProgrammaticScrollViewController {
//MARK:-Functions to subclass
// Subclass for a top view.
public func viewForTop() -> UIView? {
open func viewForTop() -> UIView? {
return nil
}
// Subclass for a middle view.
public func viewForMiddle() -> UIView? {
open func viewForMiddle() -> UIView? {
return nil
}
// Subclass for a bottom view.
public func viewForBottom() -> UIView? {
open func viewForBottom() -> UIView? {
return nil
}
// If a value is set, the middle view is pinned this value below the top view, if not, space is left to fill.
public func spaceBetweenTopAndMiddle() -> CGFloat? {
open func spaceBetweenTopAndMiddle() -> CGFloat? {
return nil
}
// If a value is set, the middle view is pinned this value above the bottom view, if not, space is left to fill.
public func spaceBetweenMiddleAndBottom() -> CGFloat? {
open func spaceBetweenMiddleAndBottom() -> CGFloat? {
return nil
}
}
@ -246,7 +246,7 @@ extension ThreeLayerViewController {
//MARK:-Animation
extension ThreeLayerViewController {
public override func setupIntroAnimations() {
open override func setupIntroAnimations() {
if let topView = topView, topView.subviews.count > 0 {
introAnimationManager?.addAnimation(animation: MVMAnimations.fadeUpAnimation(view: topView))
}

View File

@ -112,4 +112,9 @@ FOUNDATION_EXPORT const unsigned char MVMCoreUIVersionString[];
#import <MVMCoreUI/PrimaryButtonView.h>
#import <MVMCoreUI/MVMCoreUIMoleculeViewProtocol.h>
#import <MVMCoreUI/MVMCoreUIFormValidator.h>
#import <MVMCoreUI/MVMCoreUIFormValidationProtocol.h>
#pragma mark - Templates

View File

@ -0,0 +1,14 @@
//
// FormValidator.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/26/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import Foundation
class FormValidator: NSObject {
var delegate: MVMCoreUIFormValidationProtocol?
var molecules: [MVMCoreUIFormValidationProtocol]?
}

View File

@ -0,0 +1,33 @@
//
// MVMCoreUIFormValidator+FormParams.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/21/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import Foundation
@objc public extension MVMCoreUIFormValidator {
@objc public func addFormParams(requestParameters: MVMCoreRequestParameters) {
DispatchQueue.main.sync {
requestParameters.add(self.getFormParams())
}
}
@objc public func getFormParams() -> [String: Any] {
var extraParam: [String: Any] = [:]
for molecule in self.molecules {
if let molecule = molecule as? MVMCoreUIFormValidationProtocol,
let formFieldName = molecule.formFieldName,
let formFieldValue = molecule.formFieldValue,
let fieldName = formFieldName(),
let fieldValue = formFieldValue() {
extraParam[fieldName] = fieldValue
}
}
return extraParam
}
}

View File

@ -0,0 +1,46 @@
//
// MVMCoreUIFormValidator+TextFields.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/21/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import Foundation
@objc extension MVMCoreUIFormValidator: UITextFieldDelegate, UITextViewDelegate, MFTextFieldDelegate{
@objc public func textFieldDidEndEditing(_ textField: UITextField) {
setEnabledByValidity()
}
@objc public func dismissFieldInput(_ sender: Any?) {
if let delegate = delegate as? MFTextFieldDelegate,
let dismissFieldInput = delegate.dismissFieldInput {
dismissFieldInput(sender)
}
}
@objc public func textFieldShouldReturn(_ textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
@objc public func textFieldDidBeginEditing(_ textField: UITextField) {
if let delegate = delegate as? UITextFieldDelegate,
let textFieldDidBeginEditing = delegate.textFieldDidBeginEditing {
textFieldDidBeginEditing(textField)
}
}
@objc public func entryIsValid(_ textfield: MFTextField?) {
DispatchQueue.main.async {
self.setEnabledByValidity()
}
}
@objc public func entryIsInvalid(_ textfield: MFTextField?) {
DispatchQueue.main.async {
self.setEnabledByValidity()
}
}
}

View File

@ -0,0 +1,31 @@
//
// MVMCoreUIFormValidator.h
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/20/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "MVMCoreUIFormValidationProtocol.h"
NS_ASSUME_NONNULL_BEGIN
@class MFTextField;
@interface MVMCoreUIFormValidator : NSObject
@property (weak, nonatomic) NSObject <MVMCoreUIFormValidationProtocol>* delegate;
@property (strong, nonatomic) NSMutableArray <UIView <MVMCoreUIFormValidationProtocol>*>* molecules;
@property (nullable, copy, nonatomic) BOOL(^extraValidationBlock)(void);
- (void)setEnabledByValidity;
- (void)insertMolecule:(nonnull UIView <MVMCoreUIFormValidationProtocol>*) molecule;
+ (void)setupValidationFor:(nonnull UIView <MVMCoreUIFormValidationProtocol>*) molecule delegate:(nonnull NSObject <MVMCoreUIFormValidationProtocol>*)delegate;
@end
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,79 @@
//
// MVMCoreUIFormValidator.m
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/20/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
#import "MVMCoreUIFormValidator.h"
#import "MFTextField.h"
@import MVMCore.MVMCoreDispatchUtility;
@interface MVMCoreUIFormValidator() <MFTextFieldDelegate, UITextFieldDelegate>
@property (strong, nonatomic) NSMutableArray <MFTextField *>*textFields;
@end
@implementation MVMCoreUIFormValidator
- (void)insertMolecule:(nonnull UIView <MVMCoreUIFormValidationProtocol>*) molecule {
if (self.molecules == nil) {
self.molecules = [NSMutableArray array];
}
if (molecule) {
[self.molecules addObject:molecule];
}
}
+ (void)setupValidationFor:(nonnull UIView <MVMCoreUIFormValidationProtocol>*) molecule delegate:(nonnull NSObject <MVMCoreUIFormValidationProtocol>*)delegate {
if ([delegate conformsToProtocol:@protocol(MVMCoreUIFormValidationProtocol)]
&& [delegate respondsToSelector:@selector(formValidatorModel)]
&& [molecule conformsToProtocol:@protocol(MVMCoreUIFormValidationProtocol)]
&& [molecule respondsToSelector:@selector(setFormValidationModel:)]) {
MVMCoreUIFormValidator *validator = [delegate formValidatorModel];
validator.delegate = delegate;
[validator insertMolecule:molecule];
[molecule setFormValidationModel:validator];
}
}
- (void)setEnabledByValidity {
__block BOOL valid = YES;
[self.molecules enumerateObjectsUsingBlock:^(UIView<MVMCoreUIFormValidationProtocol> * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj conformsToProtocol:@protocol(MVMCoreUIFormValidationProtocol)]
&& [obj respondsToSelector:@selector(isValidField)]
&& [obj isValidField] == NO) {
valid = NO;
*stop = YES;
}
}];
BOOL shouldEnable = valid && (self.extraValidationBlock ? self.extraValidationBlock() : YES);
[self shouldEnable:shouldEnable];
}
- (void)shouldEnable:(BOOL) enable {
[self.molecules enumerateObjectsUsingBlock:^(UIView<MVMCoreUIFormValidationProtocol> * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if ([obj conformsToProtocol:@protocol(MVMCoreUIFormValidationProtocol)]
&& [obj respondsToSelector:@selector(enableField:)]) {
[MVMCoreDispatchUtility performBlockOnMainThread:^{
[obj enableField:enable];
}];
}
}];
}
- (void)entryIsValid:(nullable MFTextField *)textfield {
[self setEnabledByValidity];
}
- (void)entryIsInvalid:(nullable MFTextField *)textfield {
[self shouldEnable:false];
}
@end

View File

@ -10,7 +10,7 @@ import UIKit
import MVMCore
public class MFTextFieldListView: MFView {
public class MFTextFieldListView: ViewConstrainingView {
public var textFieldMapList: [[String: Any]]?
public var parentViewContoller: MFViewController?
@ -24,7 +24,19 @@ public class MFTextFieldListView: MFView {
self.primaryButton = primaryButton
super.init(frame: .zero)
}
public override func setWithJSON(_ json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) {
self.textFieldMapList = json?.arrayForKey("textFields") as? [[String : Any]]
if let threeLayerVC = delegate as? ThreeLayerViewController {
self.parentViewContoller = threeLayerVC
self.primaryButton = (threeLayerVC.bottomView as? StandardFooterView)?.twoButtonView.primaryButton
}
setupView()
}
public required init?(coder decoder: NSCoder) {
super.init(coder: decoder)
}

View File

@ -16,17 +16,17 @@ public class MoleculeStackView: MFView {
super.init(frame: frame)
}
init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) {
public init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?, additionalData: [AnyHashable : Any]?) {
super.init(frame: CGRect.zero)
setWithJSON(json, delegate: delegate, additionalData: additionalData)
}
convenience init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?, spacingBlock: ((Any) -> UIEdgeInsets)?) {
public convenience init(withJSON json: [AnyHashable : Any]?, delegate: NSObject?, spacingBlock: ((Any) -> UIEdgeInsets)?) {
self.init(withJSON: json, delegate: delegate, additionalData: nil)
self.spacingBlock = spacingBlock
}
required init?(coder aDecoder: NSCoder) {
public required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

View File

@ -11,6 +11,7 @@
@import MVMCore.NSDictionary_MFConvenience;
#import "MVMCoreUIObject.h"
#import <MVMCoreUI/MVMCoreUI-Swift.h>
#import "MFTextField.h"
@implementation MVMCoreUIMoleculeMappingObject
@ -28,7 +29,8 @@
@"standardHeader": StandardHeaderView.class,
@"moleculeStack": MoleculeStackView.class,
@"twoButtonView": PrimaryButtonView.class,
@"standardFooter": StandardFooterView.class
@"standardFooter": StandardFooterView.class,
@"textField" : MFTextField.class,
} mutableCopy];
});
return mapping;
@ -57,8 +59,9 @@
return nil;
}
UIView <MVMCoreUIMoleculeViewProtocol>*molecule = [self getMoleculeForName:moleculeName];
[molecule setWithJSON:json delegate:delegate additionalData:nil];
[molecule setWithJSON:json delegate:delegate additionalData:nil];
return molecule;
}
@end

View File

@ -0,0 +1,18 @@
//
// MVMCoreUIFormMoleculesProtocol.h
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/21/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
#import <Foundation/Foundation.h>
@protocol MVMCoreUIFormMoleculesProtocol <NSObject>
//- (BOOL)isValidField;
//- (void)enableField:(BOOL) enable;
//
//- (NSString *)formFieldName;
//- (NSString *)formFieldValue;
@end

View File

@ -0,0 +1,27 @@
//
// MVMCoreUIFormValidationProtocol.h
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/20/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
#import <Foundation/Foundation.h>
@class MVMCoreUIFormValidator;
@protocol MVMCoreUIFormValidationProtocol <NSObject>
// Returns the form validator model
- (nullable MVMCoreUIFormValidator *) formValidatorModel;
@optional
- (void)setFormValidationModel:(nonnull MVMCoreUIFormValidator *) formValidatorModel;
- (BOOL)isValidField;
- (void)enableField:(BOOL) enable;
- (nullable NSString *)formFieldName;
- (nullable id)formFieldValue;
@end

View File

@ -17,14 +17,16 @@ public class MoleculeStackCenteredTemplate: ThreeLayerViewController {
}
public override func viewForTop() -> UIView? {
guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForJSON(moleculeJSON, delegate: self) else {
guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("header"),
let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForJSON(moleculeJSON, delegate: self) else {
return nil
}
return molecule
}
override public func viewForBottom() -> UIView? {
guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"), let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForJSON(moleculeJSON, delegate: self) else {
guard let moleculeJSON = loadObject?.pageJSON?.optionalDictionaryForKey("footer"),
let molecule = MVMCoreUIMoleculeMappingObject.shared()?.getMoleculeForJSON(moleculeJSON, delegate: self) else {
return nil
}
return molecule