added extra check to ensure you aren't duplicating rules
Signed-off-by: Matt Bruce <matt.bruce@verizon.com>
This commit is contained in:
parent
c8496194f0
commit
bdaa4b5ea7
@ -56,6 +56,12 @@ import MVMCore
|
|||||||
|
|
||||||
//find the group
|
//find the group
|
||||||
if let formGroup = formRules?.first(where: {$0.groupName == field.groupName}) {
|
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)
|
formGroup.rules.append(contentsOf: internalRules)
|
||||||
} else {
|
} else {
|
||||||
//create the new group
|
//create the new group
|
||||||
|
|||||||
@ -11,10 +11,13 @@ import VDS
|
|||||||
|
|
||||||
open class VDSRuleBase: RuleAnyModelProtocol {
|
open class VDSRuleBase: RuleAnyModelProtocol {
|
||||||
open var ruleId: String?
|
open var ruleId: String?
|
||||||
|
open var ruleType: String
|
||||||
open var errorMessage: [String : String]?
|
open var errorMessage: [String : String]?
|
||||||
open var fields = [String]()
|
open var fields = [String]()
|
||||||
public init(){}
|
public init(){
|
||||||
|
ruleType = Self.identifier
|
||||||
|
}
|
||||||
|
public var type: String { ruleType }
|
||||||
open func isValid(_ formField: any FormFieldProtocol) -> Bool {
|
open func isValid(_ formField: any FormFieldProtocol) -> Bool {
|
||||||
fatalError()
|
fatalError()
|
||||||
}
|
}
|
||||||
@ -34,8 +37,8 @@ public class RuleVDSModel<ValueType>: VDSRuleBase {
|
|||||||
public init(field: String, rule: AnyRule<ValueType>) {
|
public init(field: String, rule: AnyRule<ValueType>) {
|
||||||
self.rule = rule
|
self.rule = rule
|
||||||
super.init()
|
super.init()
|
||||||
|
self.ruleType = rule.ruleType
|
||||||
self.fields = [field]
|
self.fields = [field]
|
||||||
self.ruleId = "\(rule.self)-\(Int.random(in: 1...1000))"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
required init(from decoder: any Decoder) throws {
|
required init(from decoder: any Decoder) throws {
|
||||||
@ -57,3 +60,4 @@ public class RuleVDSModel<ValueType>: VDSRuleBase {
|
|||||||
return valid
|
return valid
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user