From 3a32d780045c2d0427da03a1661c97f29aa10671 Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Mon, 28 Oct 2019 16:25:25 -0400 Subject: [PATCH] form validation fixes --- MVMCoreUI/Atoms/Views/Checkbox.swift | 21 +++++++++++---------- MVMCoreUI/Atoms/Views/MVMCoreUISwitch.m | 2 +- MVMCoreUI/Molecules/RadioButtonModel.swift | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/MVMCoreUI/Atoms/Views/Checkbox.swift b/MVMCoreUI/Atoms/Views/Checkbox.swift index 5ee397a3..e5a82b1d 100644 --- a/MVMCoreUI/Atoms/Views/Checkbox.swift +++ b/MVMCoreUI/Atoms/Views/Checkbox.swift @@ -19,7 +19,8 @@ import MVMCore // Form Validation var isRequired = false var fieldKey: String? - var delegateObject: DelegateObject? + var groupName: String? + var delegateObject: MVMCoreUIDelegateObject? public static let defaultHeightWidth: CGFloat = 18.0 @@ -104,12 +105,8 @@ import MVMCore layoutIfNeeded() shapeLayer?.removeAllAnimations() - updateCheckboxUI(isSelected: isSelected, isAnimated: isAnimated) - - if let delegate = delegateObject as? FormValidationProtocol { - delegate.formValidatorModel?()?.enableByValidation() - } - + updateCheckboxUI(isSelected: isSelected, isAnimated: isAnimated) + FormValidator.enableByValidationWith(delegate: delegateObject?.formValidationProtocol) updateAccessibilityLabel() } } @@ -211,7 +208,6 @@ import MVMCore /// This will toggle the state of the Checkbox and execute the actionBlock if provided. public func toggleAndAction() { - isSelected.toggle() actionBlock?() } @@ -409,7 +405,8 @@ import MVMCore FormValidator.setupValidation(molecule: self, delegate: delegateObject?.formValidationProtocol) guard let dictionary = json else { return } - + + groupName = dictionary.optionalStringForKey("groupName") if let fieldKey = dictionary[KeyFieldKey] as? String { self.fieldKey = fieldKey } @@ -463,7 +460,11 @@ import MVMCore } // MARK:- FormValidationProtocol -extension Checkbox: FormValidationProtocol { +extension Checkbox: FormValidationFormFieldProtocol { + + public func formFieldGroupName() -> String? { + return groupName + } public func isValidField() -> Bool { return isRequired ? isSelected : true diff --git a/MVMCoreUI/Atoms/Views/MVMCoreUISwitch.m b/MVMCoreUI/Atoms/Views/MVMCoreUISwitch.m index a3bbea81..2e32d73b 100644 --- a/MVMCoreUI/Atoms/Views/MVMCoreUISwitch.m +++ b/MVMCoreUI/Atoms/Views/MVMCoreUISwitch.m @@ -22,7 +22,7 @@ const CGFloat SwitchKnobWidth = 20; const CGFloat SwitchKnobHeight = 20; const CGFloat SwitchShakeIntensity = 2; -@interface MVMCoreUISwitch () +@interface MVMCoreUISwitch () @property (weak, nonatomic) UIView *baseView; @property (weak, nonatomic) UIView *knobView; diff --git a/MVMCoreUI/Molecules/RadioButtonModel.swift b/MVMCoreUI/Molecules/RadioButtonModel.swift index e2e6b27b..bb70dec7 100644 --- a/MVMCoreUI/Molecules/RadioButtonModel.swift +++ b/MVMCoreUI/Molecules/RadioButtonModel.swift @@ -33,7 +33,7 @@ import UIKit } } -// MARK: - FormValidationProtocol +// MARK: - FormValidationFormFieldProtocol extension RadioButtonModel: FormValidationFormFieldProtocol { public func formFieldGroupName() -> String? { return selectedRadioButton?.formFieldGroupName() ?? self.fieldGroupName