This commit is contained in:
Suresh, Kamlesh 2020-03-13 12:31:32 -04:00
parent 8b1b6ea454
commit f888358336
5 changed files with 9 additions and 9 deletions

View File

@ -44,7 +44,7 @@ import UIKit
private var observingForChange: Bool = false private var observingForChange: Bool = false
/// Validate on each entry in the textField. Default: false /// Validate on each entry in the textField. Default: true
public var validateEachCharacter: Bool = true public var validateEachCharacter: Bool = true
/// Validate when user resigns editing. Default: true /// Validate when user resigns editing. Default: true

View File

@ -66,7 +66,7 @@ import MVMCore
public func validate(_ groupName: String, _ actionModel: FormActionFieldProtocol, _ rules: [RulesProtocol]) { public func validate(_ groupName: String, _ actionModel: FormActionFieldProtocol, _ rules: [RulesProtocol]) {
var valid = true var valid = true
for rule in rules { for rule in rules {
valid = valid && rule.isValid(self) valid = valid && rule.isValid(fieldMolecules)
if !valid { if !valid {
break break
} }

View File

@ -18,9 +18,9 @@ public class RuleAnyValueChangedModel: RulesProtocol {
return formField.baseValue != formField.formFieldValue() return formField.baseValue != formField.formFieldValue()
} }
public func isValid(_ formValidator: FormValidator) -> Bool { public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
for formKey in fields { for formKey in fields {
guard let formField = formValidator.formField(for: formKey) else { guard let formField = fieldMolecules[formKey] else {
continue continue
} }
if isValid(formField) { if isValid(formField) {

View File

@ -18,11 +18,11 @@ public class RuleEqualsModel: RulesProtocol {
return false return false
} }
public func isValid(_ formValidator: FormValidator) -> Bool { public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
var valid = true var valid = true
var compareValue: AnyHashable? var compareValue: AnyHashable?
for formKey in fields { for formKey in fields {
guard let formField = formValidator.formField(for: formKey) else { guard let formField = fieldMolecules[formKey] else {
continue continue
} }

View File

@ -16,7 +16,7 @@ public enum RulesCodingKey: String, CodingKey {
public protocol RulesProtocol: ModelProtocol { public protocol RulesProtocol: ModelProtocol {
var type: String { get set } var type: String { get set }
var fields: [String] { get set } var fields: [String] { get set }
func isValid(_ formValidator: FormValidator) -> Bool func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool
func isValid(_ formField: FormFieldProtocol) -> Bool func isValid(_ formField: FormFieldProtocol) -> Bool
func setValid(_ formField: FormFieldProtocol, _ isValid: Bool) func setValid(_ formField: FormFieldProtocol, _ isValid: Bool)
} }
@ -35,10 +35,10 @@ public extension RulesProtocol {
return "\(RulesProtocol.self)" return "\(RulesProtocol.self)"
} }
func isValid(_ formValidator: FormValidator) -> Bool { func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
var valid = true var valid = true
for formKey in fields { for formKey in fields {
guard let formField = formValidator.formField(for: formKey) else { guard let formField = fieldMolecules[formKey] else {
continue continue
} }
let fieldValidity = isValid(formField) let fieldValidity = isValid(formField)