From 4c96cdda15e9e344e2d453462efc441edb1d6eeb Mon Sep 17 00:00:00 2001 From: "Suresh, Kamlesh" Date: Fri, 10 Apr 2020 17:56:08 -0400 Subject: [PATCH] more fixes --- .../Rules/Rules/RuleAnyValueChangedModel.swift | 7 ++----- MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift | 3 ++- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift index 7cf24cd5..450fdb2a 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RuleAnyValueChangedModel.swift @@ -26,16 +26,13 @@ public class RuleAnyValueChangedModel: RulesProtocol { return formField.baseValue != formField.formFieldValue() } - public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { - + public func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { for formKey in fields { guard let formField = fieldMolecules[formKey] else { continue } - if isValid(formField) { return true } - } - + } return false } } diff --git a/MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift b/MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift index 70d30506..ee768a70 100644 --- a/MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift +++ b/MVMCoreUI/FormUIHelpers/Rules/Rules/RulesProtocol.swift @@ -23,7 +23,7 @@ public protocol RulesProtocol: ModelProtocol { // Returns if a given field is valid according to the rule func isValid(_ formField: FormFieldProtocol) -> Bool - // Returns if a the rule is valid + // Validates the rule and returns the result. func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool } @@ -41,6 +41,7 @@ public extension RulesProtocol { return "\(RulesProtocol.self)" } + // Indiviidual rule can override the function to validate based on the rule type. func validate(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool { var valid = true for formKey in fields {