latest state of validator
This commit is contained in:
commit
3625a115b9
@ -785,20 +785,6 @@
|
||||
path = ModelProtocols;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
011D9583240422BF000E3791 /* New */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
011D958A24042794000E3791 /* Rules */,
|
||||
011D95882404249B000E3791 /* FormProtocol.swift */,
|
||||
011D95AC2406BB57000E3791 /* FormHolderProtocol.swift */,
|
||||
011D95AA2405C553000E3791 /* FormItemProtocol.swift */,
|
||||
011D958624042492000E3791 /* FormFieldProtocol.swift */,
|
||||
011D95A824057AC7000E3791 /* FormActionFieldProtocol.swift */,
|
||||
011D9601240DA20A000E3791 /* ValidProtocol.swift */,
|
||||
);
|
||||
path = New;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
011D958A24042794000E3791 /* Rules */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -811,7 +797,8 @@
|
||||
011D95A4240455DC000E3791 /* FormGroupRule.swift */,
|
||||
0A69F610241BDEA700F7231B /* RuleAnyRequiredModel.swift */,
|
||||
);
|
||||
path = Rules;
|
||||
name = Rules;
|
||||
path = Rules/Rules;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
012A88EF23985E0100FE3DA1 /* CustomPrimitives */ = {
|
||||
@ -833,8 +820,14 @@
|
||||
01C74D87224298E2009C25A3 /* FormUIHelpers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
011D9583240422BF000E3791 /* New */,
|
||||
011D95882404249B000E3791 /* FormProtocol.swift */,
|
||||
011D95AC2406BB57000E3791 /* FormHolderProtocol.swift */,
|
||||
011D95AA2405C553000E3791 /* FormItemProtocol.swift */,
|
||||
011D958624042492000E3791 /* FormFieldProtocol.swift */,
|
||||
011D95A824057AC7000E3791 /* FormActionFieldProtocol.swift */,
|
||||
011D9601240DA20A000E3791 /* ValidProtocol.swift */,
|
||||
0105618A224BBE7700E1557D /* FormValidator.swift */,
|
||||
011D958A24042794000E3791 /* Rules */,
|
||||
);
|
||||
path = FormUIHelpers;
|
||||
sourceTree = "<group>";
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -35,10 +35,10 @@ public class RuleAnyRequiredModel: RulesProtocol {
|
||||
return false
|
||||
}
|
||||
|
||||
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 { continue }
|
||||
guard let formField = fieldMolecules[formKey] else { continue }
|
||||
|
||||
if isValid(formField) {
|
||||
return true
|
||||
@ -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,9 +16,8 @@ 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 isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> Bool
|
||||
func setValid(_ formField: FormFieldProtocol, _ isValid: Bool)
|
||||
}
|
||||
|
||||
@ -36,12 +35,11 @@ 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 { continue }
|
||||
guard let formField = fieldMolecules[formKey] else { continue }
|
||||
let fieldValidity = isValid(formField)
|
||||
setValid(formField, fieldValidity)
|
||||
valid = valid && fieldValidity
|
||||
Loading…
Reference in New Issue
Block a user