refactor
This commit is contained in:
parent
8b1b6ea454
commit
f888358336
@ -44,7 +44,7 @@ import UIKit
|
||||
|
||||
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
|
||||
|
||||
/// Validate when user resigns editing. Default: true
|
||||
|
||||
@ -66,7 +66,7 @@ import MVMCore
|
||||
public func validate(_ groupName: String, _ actionModel: FormActionFieldProtocol, _ rules: [RulesProtocol]) {
|
||||
var valid = true
|
||||
for rule in rules {
|
||||
valid = valid && rule.isValid(self)
|
||||
valid = valid && rule.isValid(fieldMolecules)
|
||||
if !valid {
|
||||
break
|
||||
}
|
||||
|
||||
@ -18,9 +18,9 @@ public class RuleAnyValueChangedModel: RulesProtocol {
|
||||
return formField.baseValue != formField.formFieldValue()
|
||||
}
|
||||
|
||||
public func isValid(_ formValidator: FormValidator) -> Bool {
|
||||
public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
|
||||
for formKey in fields {
|
||||
guard let formField = formValidator.formField(for: formKey) else {
|
||||
guard let formField = fieldMolecules[formKey] else {
|
||||
continue
|
||||
}
|
||||
if isValid(formField) {
|
||||
|
||||
@ -18,11 +18,11 @@ public class RuleEqualsModel: RulesProtocol {
|
||||
return false
|
||||
}
|
||||
|
||||
public func isValid(_ formValidator: FormValidator) -> Bool {
|
||||
public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
|
||||
var valid = true
|
||||
var compareValue: AnyHashable?
|
||||
for formKey in fields {
|
||||
guard let formField = formValidator.formField(for: formKey) else {
|
||||
guard let formField = fieldMolecules[formKey] else {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@ -16,7 +16,7 @@ public enum RulesCodingKey: String, CodingKey {
|
||||
public protocol RulesProtocol: ModelProtocol {
|
||||
var type: 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 setValid(_ formField: FormFieldProtocol, _ isValid: Bool)
|
||||
}
|
||||
@ -35,10 +35,10 @@ public extension RulesProtocol {
|
||||
return "\(RulesProtocol.self)"
|
||||
}
|
||||
|
||||
func isValid(_ formValidator: FormValidator) -> Bool {
|
||||
func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool {
|
||||
var valid = true
|
||||
for formKey in fields {
|
||||
guard let formField = formValidator.formField(for: formKey) else {
|
||||
guard let formField = fieldMolecules[formKey] else {
|
||||
continue
|
||||
}
|
||||
let fieldValidity = isValid(formField)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user