comments and formatting
This commit is contained in:
parent
bb802af681
commit
15911265a7
@ -74,13 +74,13 @@ import MVMCore
|
|||||||
/// Validates all rule groups. Returns if valid
|
/// Validates all rule groups. Returns if valid
|
||||||
public func validate() -> Bool {
|
public func validate() -> Bool {
|
||||||
var valid = true
|
var valid = true
|
||||||
guard let formRules = formRules else {
|
guard let formRules = formRules else { return valid }
|
||||||
return valid
|
|
||||||
}
|
|
||||||
for group in formRules {
|
for group in formRules {
|
||||||
let groupValid = validateGroup(group)
|
let groupValid = validateGroup(group)
|
||||||
valid = valid && groupValid
|
valid = valid && groupValid
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,13 +138,16 @@ import MVMCore
|
|||||||
|
|
||||||
// TODO: Temporary hacks, rewrite architecture to support this.
|
// TODO: Temporary hacks, rewrite architecture to support this.
|
||||||
public extension FormValidator {
|
public extension FormValidator {
|
||||||
|
|
||||||
func getGroupName(forPageType pageType: String?) -> String? {
|
func getGroupName(forPageType pageType: String?) -> String? {
|
||||||
|
|
||||||
for actionItem in groupWatchers {
|
for actionItem in groupWatchers {
|
||||||
if let buttonModel = actionItem as? ButtonModel,
|
if let buttonModel = actionItem as? ButtonModel,
|
||||||
pageType == (buttonModel.action as? ActionOpenPageModel)?.pageType {
|
pageType == (buttonModel.action as? ActionOpenPageModel)?.pageType {
|
||||||
return buttonModel.groupName
|
return buttonModel.groupName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,19 +11,35 @@ import Foundation
|
|||||||
|
|
||||||
|
|
||||||
open class FormGroupRule: Codable {
|
open class FormGroupRule: Codable {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
var groupName: String
|
var groupName: String
|
||||||
var rules: [RulesProtocol]
|
var rules: [RulesProtocol]
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Initializer
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
init(_ groupName: String, _ rules: [RulesProtocol]) {
|
init(_ groupName: String, _ rules: [RulesProtocol]) {
|
||||||
self.groupName = groupName
|
self.groupName = groupName
|
||||||
self.rules = rules
|
self.rules = rules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Keys
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case groupName
|
case groupName
|
||||||
case rules
|
case rules
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Codec
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
let typeContainer = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
self.groupName = try typeContainer.decode(String.self, forKey: .groupName)
|
self.groupName = try typeContainer.decode(String.self, forKey: .groupName)
|
||||||
|
|||||||
@ -9,11 +9,18 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
public class RuleAllValueChangedModel: RulesProtocol {
|
public class RuleAllValueChangedModel: RulesProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "allValueChanged"
|
public static var identifier: String = "allValueChanged"
|
||||||
public var type: String = RuleAllValueChangedModel.identifier
|
public var type: String = RuleAllValueChangedModel.identifier
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Validation
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
||||||
return formField.baseValue != formField.formFieldValue()
|
return formField.baseValue != formField.formFieldValue()
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,31 +10,41 @@ import Foundation
|
|||||||
|
|
||||||
|
|
||||||
public class RuleEqualsModel: RulesProtocol {
|
public class RuleEqualsModel: RulesProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "equals"
|
public static var identifier: String = "equals"
|
||||||
public var type: String = RuleEqualsModel.identifier
|
public var type: String = RuleEqualsModel.identifier
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Validation
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
public func isValid(_ fieldMolecules: [String: FormFieldProtocol]) -> 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 = fieldMolecules[formKey] else {
|
guard let formField = fieldMolecules[formKey] else { continue }
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if compareValue == nil {
|
if compareValue == nil {
|
||||||
compareValue = formField.formFieldValue()
|
compareValue = formField.formFieldValue()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if compareValue != formField.formFieldValue(){
|
|
||||||
|
if compareValue != formField.formFieldValue() {
|
||||||
valid = false
|
valid = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,16 +8,27 @@
|
|||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
|
||||||
public class RuleRegexModel: RulesProtocol {
|
public class RuleRegexModel: RulesProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "regex"
|
public static var identifier: String = "regex"
|
||||||
public var type: String = RuleRegexModel.identifier
|
public var type: String = RuleRegexModel.identifier
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
public var regex: String
|
public var regex: String
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
||||||
|
|
||||||
if let stringToValidate = formField.formFieldValue() as? String {
|
if let stringToValidate = formField.formFieldValue() as? String {
|
||||||
return MVMCoreUIUtility.validate(stringToValidate, withRegularExpression: regex)
|
return MVMCoreUIUtility.validate(stringToValidate, withRegularExpression: regex)
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,21 +10,30 @@ import Foundation
|
|||||||
|
|
||||||
|
|
||||||
public class RuleRequiredModel: RulesProtocol {
|
public class RuleRequiredModel: RulesProtocol {
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Properties
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public static var identifier: String = "allRequired"
|
public static var identifier: String = "allRequired"
|
||||||
public var type: String = RuleRequiredModel.identifier
|
public var type: String = RuleRequiredModel.identifier
|
||||||
public var fields: [String]
|
public var fields: [String]
|
||||||
|
|
||||||
|
//--------------------------------------------------
|
||||||
|
// MARK: - Validation
|
||||||
|
//--------------------------------------------------
|
||||||
|
|
||||||
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
public func isValid(_ formField: FormFieldProtocol) -> Bool {
|
||||||
guard let value = formField.formFieldValue() else {
|
guard let value = formField.formFieldValue() else { return false }
|
||||||
return false
|
|
||||||
}
|
|
||||||
var valid = true
|
var valid = true
|
||||||
|
|
||||||
if let valueString = value as? String {
|
if let valueString = value as? String {
|
||||||
valid = valueString.count > 0
|
valid = valueString.count > 0
|
||||||
|
|
||||||
} else if let valueBool = value as? Bool {
|
} else if let valueBool = value as? Bool {
|
||||||
valid = valueBool
|
valid = valueBool
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user