improvement
This commit is contained in:
parent
5df8ad42f3
commit
ff3055a4c7
@ -11,7 +11,6 @@
|
||||
0105618E224BBE7700E1557D /* FormValidator+TextFields.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */; };
|
||||
0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */; };
|
||||
01056191224BBE8000E1557D /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01056190224BBE7F00E1557D /* FormValidationProtocol.swift */; };
|
||||
01BDA2D722442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 01BDA2D622442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h */; };
|
||||
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, ); }; };
|
||||
@ -168,7 +167,6 @@
|
||||
0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+TextFields.swift"; sourceTree = "<group>"; };
|
||||
0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "FormValidator+FormParams.swift"; sourceTree = "<group>"; };
|
||||
01056190224BBE7F00E1557D /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = "<group>"; };
|
||||
01BDA2D622442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = MVMCoreUIFormMoleculesProtocol.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>"; };
|
||||
@ -340,7 +338,6 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
01056190224BBE7F00E1557D /* FormValidationProtocol.swift */,
|
||||
01BDA2D622442F59001DACC9 /* MVMCoreUIFormMoleculesProtocol.h */,
|
||||
);
|
||||
path = Protocols;
|
||||
sourceTree = "<group>";
|
||||
@ -775,7 +772,6 @@
|
||||
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 */,
|
||||
|
||||
@ -760,14 +760,6 @@
|
||||
|
||||
#pragma mark - FormValidationProtocol
|
||||
|
||||
- (nullable FormValidator*) formValidatorModel {
|
||||
return self.formValidator;
|
||||
}
|
||||
|
||||
- (void)setFormValidationModel:(nonnull FormValidator*) formValidatorModel {
|
||||
self.formValidator = formValidatorModel;
|
||||
}
|
||||
|
||||
- (void)enableField:(BOOL) enable {
|
||||
|
||||
if (self.validationRequired == NO) {
|
||||
|
||||
@ -24,7 +24,6 @@
|
||||
|
||||
@interface MFTextField() <FormValidationProtocol>
|
||||
|
||||
@property (strong, nonatomic) FormValidator* formValidator;
|
||||
@property (strong, nonatomic) UIColor *customPlaceHolderColor;
|
||||
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *separatorHeightConstraint;
|
||||
@property (strong, nonatomic) UIBezierPath *borderPath;
|
||||
@ -113,14 +112,13 @@
|
||||
[FormValidator setupValidationWithMolecule:self delegate: (id<FormValidationProtocol>)delegate];
|
||||
|
||||
[self setWithMap:json bothDelegates:delegate];
|
||||
self.mfTextFieldDelegate = self.formValidator;
|
||||
self.uiTextFieldDelegate = self.formValidator;
|
||||
|
||||
FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:(id<FormValidationProtocol>)delegate];
|
||||
self.mfTextFieldDelegate = formValidator;
|
||||
self.uiTextFieldDelegate = formValidator;
|
||||
[self setVerticalPadding:[MFStyler defaultHorizontalPaddingForApplicationWidth]];
|
||||
}
|
||||
|
||||
|
||||
|
||||
- (void) setVerticalPadding:(CGFloat) padding {
|
||||
self.textContainerLeftPin.constant = padding;
|
||||
self.errorLableLeftPin.constant = padding;
|
||||
@ -562,14 +560,6 @@
|
||||
|
||||
#pragma mark - MVMCoreUIMoleculeViewProtocol
|
||||
|
||||
- (nullable FormValidator*) formValidatorModel {
|
||||
return self.formValidator;
|
||||
}
|
||||
|
||||
- (void)setFormValidationModel:(nonnull FormValidator*) formValidatorModel {
|
||||
self.formValidator = formValidatorModel;
|
||||
}
|
||||
|
||||
- (BOOL) isValidField {
|
||||
return self.valid;
|
||||
}
|
||||
|
||||
@ -18,20 +18,26 @@ import UIKit
|
||||
public func insertMolecule(_ molecule: UIView & FormValidationProtocol) {
|
||||
molecules.append(molecule)
|
||||
}
|
||||
|
||||
public static func getFormValidatorFor(delegate: FormValidationProtocol) -> FormValidator? {
|
||||
if let delegateFormValidatorModel = delegate.formValidatorModel,
|
||||
let validator = delegateFormValidatorModel() {
|
||||
return validator
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
public static func setupValidation(molecule: UIView & FormValidationProtocol, delegate: FormValidationProtocol?) {
|
||||
if let delegateFormValidatorModel = delegate?.formValidatorModel,
|
||||
let setFormValidationModel = molecule.setFormValidationModel,
|
||||
let validator = delegateFormValidatorModel() {
|
||||
|
||||
|
||||
validator.delegate = delegate
|
||||
validator.insertMolecule(molecule)
|
||||
setFormValidationModel(validator)
|
||||
}
|
||||
}
|
||||
|
||||
public func enableByValidation() {
|
||||
|
||||
var valid = true
|
||||
for molecule in molecules {
|
||||
if let isValidField = molecule.isValidField,
|
||||
@ -39,7 +45,6 @@ import UIKit
|
||||
valid = false
|
||||
}
|
||||
}
|
||||
|
||||
let enableField = valid && (extraValidationBlock?() ?? true)
|
||||
shouldEnable(enableField)
|
||||
}
|
||||
|
||||
@ -1,29 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class MFTextField;
|
||||
|
||||
@interface MVMCoreUIFormValidator : NSObject
|
||||
|
||||
@property (weak, nonatomic) NSObject <FormValidationProtocol>* delegate;
|
||||
@property (strong, nonatomic) NSMutableArray <UIView <FormValidationProtocol>*>* molecules;
|
||||
|
||||
@property (nullable, copy, nonatomic) BOOL(^extraValidationBlock)(void);
|
||||
|
||||
- (void)setEnabledByValidity;
|
||||
- (void)insertMolecule:(nonnull UIView <FormValidationProtocol>*) molecule;
|
||||
|
||||
+ (void)setupValidationFor:(nonnull UIView <FormValidationProtocol>*) molecule delegate:(nonnull NSObject <FormValidationProtocol>*)delegate;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@ -1,75 +0,0 @@
|
||||
//
|
||||
// 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;
|
||||
|
||||
|
||||
@implementation MVMCoreUIFormValidator
|
||||
|
||||
|
||||
- (void)insertMolecule:(nonnull UIView <FormValidationProtocol>*) molecule {
|
||||
if (self.molecules == nil) {
|
||||
self.molecules = [NSMutableArray array];
|
||||
}
|
||||
if (molecule) {
|
||||
[self.molecules addObject:molecule];
|
||||
}
|
||||
}
|
||||
|
||||
+ (void)setupValidationFor:(nonnull UIView <FormValidationProtocol>*) molecule delegate:(nonnull NSObject <FormValidationProtocol>*)delegate {
|
||||
if ([delegate conformsToProtocol:@protocol(FormValidationProtocol)]
|
||||
&& [delegate respondsToSelector:@selector(formValidatorModel)]
|
||||
&& [molecule conformsToProtocol:@protocol(FormValidationProtocol)]
|
||||
&& [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<FormValidationProtocol> * _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<FormValidationProtocol> * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
||||
if ([obj conformsToProtocol:@protocol(FormValidationProtocol)]
|
||||
&& [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
|
||||
@ -24,18 +24,6 @@ public class MFTextFieldListView: ViewConstrainingView {
|
||||
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)
|
||||
|
||||
@ -10,9 +10,7 @@ import Foundation
|
||||
|
||||
@objc public protocol FormValidationProtocol: NSObjectProtocol {
|
||||
|
||||
@objc func formValidatorModel() -> FormValidator?
|
||||
|
||||
@objc optional func setFormValidationModel(_ formValidatorModel:FormValidator)
|
||||
@objc optional func formValidatorModel() -> FormValidator?
|
||||
@objc optional func isValidField() -> Bool
|
||||
@objc optional func enableField(_ enable: Bool)
|
||||
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
@ -1,29 +0,0 @@
|
||||
//
|
||||
// MVMCoreUIFormValidationProtocol.h
|
||||
// MVMCoreUI
|
||||
//
|
||||
// Created by Suresh, Kamlesh on 3/20/19.
|
||||
// Copyright © 2019 Verizon Wireless. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
//#import <MVMCoreUI/MVMCoreUI-Swift.h>
|
||||
//#import "MVMCoreUI-Swift.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
|
||||
Loading…
Reference in New Issue
Block a user