This commit is contained in:
Suresh, Kamlesh 2020-03-04 10:52:40 -05:00
parent 3ec024ff27
commit 9d8953d229
10 changed files with 50 additions and 234 deletions

View File

@ -11,7 +11,6 @@
0103B84E23D7E33A009C315C /* HeadlineBodyToggleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */; };
0105618D224BBE7700E1557D /* FormValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0105618A224BBE7700E1557D /* FormValidator.swift */; };
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 */; };
0116A4E5228B19640094F3ED /* RadioButtonSelectionHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0116A4E4228B19640094F3ED /* RadioButtonSelectionHelper.swift */; };
011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */; };
011B58F223A2AE2C0085F53C /* DropDownListItemModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */; };
@ -64,7 +63,6 @@
017BEB4A236235BA0024EF95 /* ModelMoleculeViewProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */; };
017BEB7B236763000024EF95 /* LineModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7A236763000024EF95 /* LineModel.swift */; };
017BEB7F23676E870024EF95 /* MoleculeObjectMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */; };
0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0198F79E225679870066C936 /* FormValidationProtocol.swift */; };
0198F7A62256A80B0066C936 /* MFRadioButton.h in Headers */ = {isa = PBXBuildFile; fileRef = 0198F7A02256A80A0066C936 /* MFRadioButton.h */; settings = {ATTRIBUTES = (Public, ); }; };
0198F7A82256A80B0066C936 /* MFRadioButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 0198F7A22256A80A0066C936 /* MFRadioButton.m */; };
01C851D323CF9E740021F976 /* LabelToggleModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01C851D223CF9E740021F976 /* LabelToggleModel.swift */; };
@ -381,7 +379,6 @@
0103B84D23D7E33A009C315C /* HeadlineBodyToggleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HeadlineBodyToggleModel.swift; sourceTree = "<group>"; };
0105618A224BBE7700E1557D /* FormValidator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidator.swift; sourceTree = "<group>"; };
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>"; };
0116A4E4228B19640094F3ED /* RadioButtonSelectionHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RadioButtonSelectionHelper.swift; sourceTree = "<group>"; };
011B58EF23A2AA980085F53C /* ListItemModelProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListItemModelProtocol.swift; sourceTree = "<group>"; };
011B58F123A2AE2C0085F53C /* DropDownListItemModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownListItemModel.swift; sourceTree = "<group>"; };
@ -434,7 +431,6 @@
017BEB49236235BA0024EF95 /* ModelMoleculeViewProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ModelMoleculeViewProtocol.swift; sourceTree = "<group>"; };
017BEB7A236763000024EF95 /* LineModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineModel.swift; sourceTree = "<group>"; };
017BEB7E23676E870024EF95 /* MoleculeObjectMapping.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MoleculeObjectMapping.swift; sourceTree = "<group>"; };
0198F79E225679870066C936 /* FormValidationProtocol.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FormValidationProtocol.swift; sourceTree = "<group>"; };
0198F7A02256A80A0066C936 /* MFRadioButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MFRadioButton.h; sourceTree = "<group>"; };
0198F7A22256A80A0066C936 /* MFRadioButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MFRadioButton.m; sourceTree = "<group>"; };
01C851D223CF9E740021F976 /* LabelToggleModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LabelToggleModel.swift; sourceTree = "<group>"; };
@ -827,9 +823,7 @@
isa = PBXGroup;
children = (
011D9583240422BF000E3791 /* New */,
0198F79E225679870066C936 /* FormValidationProtocol.swift */,
0105618A224BBE7700E1557D /* FormValidator.swift */,
0105618C224BBE7700E1557D /* FormValidator+FormParams.swift */,
0105618B224BBE7700E1557D /* FormValidator+TextFields.swift */,
);
path = FormUIHelpers;
@ -1896,7 +1890,6 @@
0A7EF85D23D8A95600B2AAD1 /* TextEntryFieldModel.swift in Sources */,
D2D6CD4222E78FAB00D701B8 /* ThreeLayerTemplate.swift in Sources */,
01EB368F23609801006832FA /* LabelModel.swift in Sources */,
0105618F224BBE7700E1557D /* FormValidator+FormParams.swift in Sources */,
01F2A03223A4498200D954D8 /* CaretLinkModel.swift in Sources */,
0A7BAFA1232BE61800FB8E22 /* Checkbox.swift in Sources */,
011B58F023A2AA980085F53C /* ListItemModelProtocol.swift in Sources */,
@ -1966,7 +1959,6 @@
01EB3684236097C0006832FA /* MoleculeModelProtocol.swift in Sources */,
D27CD4102339057800C1DC07 /* EyebrowHeadlineBodyLink.swift in Sources */,
D29DF11D21E684A9003B2FB9 /* MVMCoreUISplitViewController.m in Sources */,
0198F79F225679880066C936 /* FormValidationProtocol.swift in Sources */,
D243859923A16B1800332775 /* Container.swift in Sources */,
D2C521A923EDE79E00CA2634 /* ViewController.swift in Sources */,
D260105B23D0BB7100764D80 /* StackModelProtocol.swift in Sources */,

View File

@ -48,8 +48,6 @@ import UIKit
//--------------------------------------------------
public var isValid: Bool = false
public var fieldKey: String?
public var errorMessage: String?
public var standardMessage: String? {
didSet {
@ -259,10 +257,6 @@ import UIKit
} else if let isSelected = model.isSelected{
self.isSelected = isSelected
}
if let fieldKey = model.fieldKey {
self.fieldKey = fieldKey
}
}
}
@ -300,11 +294,6 @@ extension EntryField {
if let isSelected = dictionary["isSelected"] as? Bool {
self.isSelected = isSelected
}
// Key used to send text value to server
if let fieldKey = dictionary[KeyFieldKey] as? String {
self.fieldKey = fieldKey
}
}
@objc open class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
@ -312,22 +301,6 @@ extension EntryField {
}
}
// MARK: - Form Validation
extension EntryField: FormValidationProtocol {
@objc public func isValidField() -> Bool {
return isValid
}
@objc public func formFieldName() -> String? {
return fieldKey
}
@objc public func formFieldValue() -> Any? {
return text
}
}
// MARK: - Accessibility
extension EntryField {

View File

@ -19,7 +19,7 @@ public typealias ActionBlockConfirmation = () -> (Bool)
Container: The background of the toggle control.
Knob: The circular indicator that slides on the container.
*/
@objcMembers open class Toggle: Control, MVMCoreUIViewConstrainingProtocol, FormValidationFormFieldProtocol {
@objcMembers open class Toggle: Control, MVMCoreUIViewConstrainingProtocol {
//--------------------------------------------------
// MARK: - Properties
//--------------------------------------------------
@ -339,82 +339,60 @@ public typealias ActionBlockConfirmation = () -> (Bool)
return
}
self.delegateObject = delegateObject
let toggleModelJSON = toggleModel.toJSON()
FormValidator.setupValidation(molecule: toggleModel, delegate: delegateObject?.formHolderDelegate)
setWithJSON(toggleModelJSON, delegateObject: delegateObject, additionalData: additionalData)
}
//TODO: change to setWith Model
public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
guard let dictionary = json else { return }
if let color = dictionary["onTintColor"] as? String {
containerTintColor?.on = UIColor.mfGet(forHex: color)
}
if let color = dictionary["offTintColor"] as? String {
containerTintColor?.off = UIColor.mfGet(forHex: color)
}
if let color = dictionary["onKnobTintColor"] as? String {
knobTintColor?.on = UIColor.mfGet(forHex: color)
}
if let color = dictionary["offKnobTintColor"] as? String {
knobTintColor?.off = UIColor.mfGet(forHex: color)
}
if let state = dictionary["state"] as? Bool {
changeStateNoAnimation(state)
}
if let actionMap = dictionary.optionalDictionaryForKey("action") {
didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
}
if let isAnimated = dictionary["isAnimated"] as? Bool {
self.isAnimated = isAnimated
}
if let isEnabled = dictionary["isEnabled"] as? Bool{
self.isEnabled = isEnabled
}
}
public override class func estimatedHeight(with model: MoleculeModelProtocol, _ delegateObject: MVMCoreUIDelegateObject?) -> CGFloat? {
return Self.getContainerHeight()
}
}
// MARK: - Accessibility
extension Toggle {
public func formFieldGroupName() -> String? {
return json?["groupName"] as? String
}
}
// MARK: - FormValidationProtocol
extension Toggle {
public func isValidField() -> Bool {
return isOn && json?["required"] as? Bool ?? false
}
public func formFieldName() -> String? {
return json?[KeyFieldKey] as? String ?? ""
}
public func formFieldValue() -> Any? {
return NSNumber(value: isOn)
}
}
// MARK: - MVMCoreUIMoleculeViewProtocol
extension Toggle {
public override func setWithJSON(_ json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?, additionalData: [AnyHashable: Any]?) {
super.setWithJSON(json, delegateObject: delegateObject, additionalData: additionalData)
self.delegateObject = delegateObject
// FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol)
guard let dictionary = json else { return }
if let color = dictionary["onTintColor"] as? String {
containerTintColor?.on = UIColor.mfGet(forHex: color)
}
if let color = dictionary["offTintColor"] as? String {
containerTintColor?.off = UIColor.mfGet(forHex: color)
}
if let color = dictionary["onKnobTintColor"] as? String {
knobTintColor?.on = UIColor.mfGet(forHex: color)
}
if let color = dictionary["offKnobTintColor"] as? String {
knobTintColor?.off = UIColor.mfGet(forHex: color)
}
if let state = dictionary["state"] as? Bool {
changeStateNoAnimation(state)
}
if let actionMap = dictionary.optionalDictionaryForKey("action") {
didToggleAction = { MVMCoreActionHandler.shared()?.handleAction(with: actionMap, additionalData: additionalData, delegateObject: delegateObject) }
}
if let isAnimated = dictionary["isAnimated"] as? Bool {
self.isAnimated = isAnimated
}
if let isEnabled = dictionary["isEnabled"] as? Bool{
self.isEnabled = isEnabled
}
}
public class func estimatedHeight(forRow json: [AnyHashable: Any]?, delegateObject: MVMCoreUIDelegateObject?) -> CGFloat {
return Self.getContainerHeight()

View File

@ -38,7 +38,7 @@
#import <MVMCoreUI/MVMCoreUI-Swift.h>
@import MVMAnimationFramework;
@interface MFViewController() <FormValidationProtocol>
@interface MFViewController()
// A flag for if this view controller is observing for cache updates or not.
@property (nonatomic) BOOL observingForResponseJSONUpdates;

View File

@ -1,41 +0,0 @@
//
// FormValidationProtocol.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/26/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import Foundation
@objc public protocol FormValidationProtocol: NSObjectProtocol {
// Getter method to get the FormValidator from the delegate (Mostly from the parent View Controller)
@objc optional func formValidatorModel() -> FormValidator?
}
@objc public protocol FormValidationFormFieldProtocol: FormValidationProtocol {
// Used to check the validity of the field. For example, to enable/disable the primary button.
@objc func isValidField() -> Bool
// The Field name key value pair for sending to server
@objc func formFieldName() -> String?
// Returns the group name for validation. The class should always return a value.
@objc func formFieldGroupName() -> String?
// The Field value key value pair for sending to server
@objc func formFieldValue() -> Any?
}
@objc public protocol FormValidationEnableDisableProtocol: FormValidationProtocol {
// Returns true if the button needs to be enabled/disabled based on the validation
@objc func isValidationRequired() -> Bool
// Based on the isValidField(), the fields which needs to be enabled can call this method
@objc optional func enableField(_ enable: Bool)
// Returns the list of field keys required to enable/disable
@objc optional func requiredGroups() -> [String]?
}

View File

@ -1,10 +0,0 @@
//
// MVMCoreUIFormValidator+FormParams.swift
// MVMCoreUI
//
// Created by Suresh, Kamlesh on 3/21/19.
// Copyright © 2019 Verizon Wireless. All rights reserved.
//
import Foundation

View File

@ -18,7 +18,7 @@
@import MVMCore.NSDictionary_MFConvenience;
@import MVMCore.MVMCoreJSONConstants;
@interface MFTextField() <FormValidationFormFieldProtocol>
@interface MFTextField()
@property (strong, nonatomic) UIColor *customPlaceHolderColor;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *separatorHeightConstraint;
@ -560,11 +560,8 @@
- (void)setWithJSON:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject additionalData:(NSDictionary *)additionalData {
[super setWithJSON:json delegateObject:delegateObject additionalData:additionalData];
if ([delegateObject isKindOfClass:[MVMCoreUIDelegateObject class]]) {
// [FormValidator setupValidationWithMolecule:self delegate:delegateObject.formValidationProtocol];
// FormValidator *formValidator = [FormValidator getFormValidatorForDelegate:delegateObject.formValidationProtocol];
[self setWithMap:json];
// self.mfTextFieldDelegate = formValidator;
self.mfTextFieldDelegate = delegateObject.uiTextFieldDelegate;
self.uiTextFieldDelegate = delegateObject.uiTextFieldDelegate;
[MVMCoreUICommonViewsUtility addDismissToolbar:self.textField delegate:self.uiTextFieldDelegate];
}
@ -574,24 +571,4 @@
+ (CGFloat)estimatedHeightForRow:(NSDictionary *)json delegateObject:(MVMCoreUIDelegateObject *)delegateObject {
return 76;
}
#pragma mark - FormValidationProtocol
- (BOOL)isValidField {
return self.isValid;
}
- (nullable NSString *)formFieldName {
return self.fieldKey;
}
- (nullable id)formFieldValue {
return self.text;
}
- (NSString * _Nullable)formFieldGroupName {
return self.groupName;
}
@end

View File

@ -21,7 +21,7 @@
static const CGFloat FaultTolerance = 20.f;
static const CGFloat CheckBoxHeightWidth = 18.0;
@interface MVMCoreUICheckBox () <FormValidationFormFieldProtocol, MVMCoreUIMoleculeViewProtocol>
@interface MVMCoreUICheckBox () <MVMCoreUIMoleculeViewProtocol>
@property (nonatomic, readwrite) BOOL isSelected;
@property (weak, nonatomic) UIView *checkedSquare;
@ -109,23 +109,6 @@ static const CGFloat CheckBoxHeightWidth = 18.0;
return checkBox;
}
#pragma mark - FormValidationProtocol
- (BOOL)isValidField {
if (self.isRequired) {
return self.isSelected;
}
return true;
}
- (nullable NSString *)formFieldName {
return self.fieldKey;
}
- (nullable id)formFieldValue {
return @(self.isSelected);
}
#pragma mark - inits
- (instancetype)init {

View File

@ -22,7 +22,7 @@ const CGFloat SwitchKnobWidth = 20;
const CGFloat SwitchKnobHeight = 20;
const CGFloat SwitchShakeIntensity = 2;
@interface MVMCoreUISwitch () <FormValidationFormFieldProtocol, MVMCoreUIViewConstrainingProtocol>
@interface MVMCoreUISwitch () <MVMCoreUIViewConstrainingProtocol>
@property (weak, nonatomic) UIView *baseView;
@property (weak, nonatomic) UIView *knobView;
@ -426,22 +426,4 @@ const CGFloat SwitchShakeIntensity = 2;
return [MVMCoreUIUtility hardcodedStringWithKey:@"AccToggleHint"];
}
#pragma mark FormValidationProtocol
- (NSString * _Nullable)formFieldGroupName {
return [self.json string:@"groupName"];
}
- (BOOL)isValidField {
return self.isOn && [self.json boolForKey:@"required"];
}
- (NSString *)formFieldName {
return [self.json string:KeyFieldKey];
}
- (id)formFieldValue {
return @(self.isOn);
}
@end

View File

@ -18,7 +18,7 @@
@import MVMCore.MVMCoreGetterUtility;
@import MVMCore.NSDictionary_MFConvenience;
@interface PrimaryButton() <FormValidationEnableDisableProtocol>
@interface PrimaryButton()
@property (nonatomic) BOOL smallButton;
@property (assign, nonatomic) BOOL tinyButton;
@ -781,22 +781,4 @@
}
}
#pragma mark - FormValidationEnableDisableProtocol
- (BOOL)isValidationRequired {
return self.validationRequired;
}
- (NSArray<NSString *> *)requiredGroups {
return self.requiredGroupsList;
}
- (void)enableField:(BOOL)enable {
if (!self.validationRequired) {
self.enabled = YES;
} else {
self.enabled = enable;
}
}
@end