Merge branch 'feature/vds-form-controls' into feature/atomic-vds-textArea

This commit is contained in:
Matt Bruce 2024-07-30 11:10:07 -05:00
commit 8ec3f01e2c
2 changed files with 15 additions and 5 deletions

View File

@ -56,6 +56,12 @@ import MVMCore
//find the group
if let formGroup = formRules?.first(where: {$0.groupName == field.groupName}) {
var appendingRules = [RulesProtocol]()
internalRules.forEach { internalRule in
if !formGroup.rules.contains(where: { internalRule.type == $0.type && internalRule.fields == $0.fields } ) {
appendingRules.append(internalRule)
}
}
formGroup.rules.append(contentsOf: internalRules)
} else {
//create the new group

View File

@ -9,12 +9,15 @@
import Foundation
import VDS
open class VDSRuleBase: RuleAnyModelProtocol {
open class VDSRuleBase: RuleAnyModelProtocol {
open var ruleId: String?
open var ruleType: String
open var errorMessage: [String : String]?
open var fields = [String]()
public init(){}
public init(){
ruleType = Self.identifier
}
public var type: String { ruleType }
open func isValid(_ formField: any FormFieldProtocol) -> Bool {
fatalError()
}
@ -26,7 +29,7 @@ public class RuleVDSModel<ValueType>: VDSRuleBase {
// MARK: - Properties
//--------------------------------------------------
public var rule: AnyRule<ValueType>
//--------------------------------------------------
// MARK: - Initializer
//--------------------------------------------------
@ -34,8 +37,8 @@ public class RuleVDSModel<ValueType>: VDSRuleBase {
public init(field: String, rule: AnyRule<ValueType>) {
self.rule = rule
super.init()
self.ruleType = rule.ruleType
self.fields = [field]
self.ruleId = "\(rule.self)-\(Int.random(in: 1...1000))"
}
required init(from decoder: any Decoder) throws {
@ -57,3 +60,4 @@ public class RuleVDSModel<ValueType>: VDSRuleBase {
return valid
}
}