Merge branch 'bugfix/FormGroupValidation' into 'develop'
FormGroupRule validateGroup update See merge request BPHV_MIPS/mvm_core_ui!797
This commit is contained in:
commit
d9a0c6b249
@ -111,22 +111,6 @@ import MVMCore
|
|||||||
/// - counter: keeps track of how many times causes another group validation
|
/// - counter: keeps track of how many times causes another group validation
|
||||||
/// - Returns: validity for the FormGroupRule.rules
|
/// - Returns: validity for the FormGroupRule.rules
|
||||||
public func validateGroup(_ group: FormGroupRule, counter: Int = 0) throws -> Bool {
|
public func validateGroup(_ group: FormGroupRule, counter: Int = 0) throws -> Bool {
|
||||||
let tuple = group.validate(fields)
|
|
||||||
|
|
||||||
group.rules.forEach { rule in
|
|
||||||
for formKey in rule.fields {
|
|
||||||
guard let formField = fields[formKey] as? FormRuleWatcherFieldProtocol,
|
|
||||||
let fieldValidity = tuple.fieldValidity[formKey] else { continue }
|
|
||||||
formField.setValidity(fieldValidity, rule: rule)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify the group watchers of validity.
|
|
||||||
for watcher in groupWatchers.filter({$0.groupName == group.groupName}) {
|
|
||||||
watcher.setValidity(tuple.valid)
|
|
||||||
}
|
|
||||||
|
|
||||||
var ruleChange = false
|
|
||||||
|
|
||||||
//loop the effects
|
//loop the effects
|
||||||
group.effects?.forEach({ effect in
|
group.effects?.forEach({ effect in
|
||||||
@ -140,24 +124,30 @@ import MVMCore
|
|||||||
|
|
||||||
//update the group form rules
|
//update the group form rules
|
||||||
if let ruleIds = effect.activatedRuleIds {
|
if let ruleIds = effect.activatedRuleIds {
|
||||||
let didChange = self.updateRules(for: group, with: effectTuple.valid, for: effect.fieldKey, and: ruleIds)
|
self.updateRules(for: group, with: effectTuple.valid, for: effect.fieldKey, and: ruleIds)
|
||||||
if(didChange) {
|
|
||||||
ruleChange = didChange
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if ruleChange {
|
//validate the form
|
||||||
if counter > 3 {
|
let tuple = group.validate(fields)
|
||||||
throw ValidationError.other(error: "Effect caused validation loop error")
|
|
||||||
} else {
|
//set the validity for the fields
|
||||||
return try self.validateGroup(group, counter: counter + 1)
|
group.rules.forEach { rule in
|
||||||
|
for formKey in rule.fields {
|
||||||
|
guard let formField = fields[formKey] as? FormRuleWatcherFieldProtocol,
|
||||||
|
let fieldValidity = tuple.fieldValidity[formKey] else { continue }
|
||||||
|
formField.setValidity(fieldValidity, rule: rule)
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return tuple.valid
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Notify the group watchers of validity.
|
||||||
|
for watcher in groupWatchers.filter({$0.groupName == group.groupName}) {
|
||||||
|
watcher.setValidity(tuple.valid)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tuple.valid
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Updates the Fields in which a specific rule within a FormGroupRule validates against.
|
/// Updates the Fields in which a specific rule within a FormGroupRule validates against.
|
||||||
@ -166,6 +156,7 @@ import MVMCore
|
|||||||
/// - validity: If you the fieldKey should be added or removed from a rule
|
/// - validity: If you the fieldKey should be added or removed from a rule
|
||||||
/// - fieldKey: FieldKey that will be added or removed from a rule
|
/// - fieldKey: FieldKey that will be added or removed from a rule
|
||||||
/// - ruleIds: Array of ruleIds to add or remove the fieldKey into the rule.fields property
|
/// - ruleIds: Array of ruleIds to add or remove the fieldKey into the rule.fields property
|
||||||
|
@discardableResult
|
||||||
public func updateRules(for group: FormGroupRule, with validity: Bool, for fieldKey: String, and ruleIds: [String]) -> Bool{
|
public func updateRules(for group: FormGroupRule, with validity: Bool, for fieldKey: String, and ruleIds: [String]) -> Bool{
|
||||||
//update the group rules based on the validation of this rule to show/hide
|
//update the group rules based on the validation of this rule to show/hide
|
||||||
var ruleChange = false
|
var ruleChange = false
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user