diff --git a/MVMCoreUI/FormUIHelpers/FormValidator.swift b/MVMCoreUI/FormUIHelpers/FormValidator.swift index f991926b..4a1d36c7 100644 --- a/MVMCoreUI/FormUIHelpers/FormValidator.swift +++ b/MVMCoreUI/FormUIHelpers/FormValidator.swift @@ -111,11 +111,19 @@ import MVMCore /// - counter: keeps track of how many times causes another group validation /// - Returns: validity for the FormGroupRule.rules public func validateGroup(_ group: FormGroupRule, counter: Int = 0) throws -> Bool { - let valid = group.validate(fields) + 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(valid) + watcher.setValidity(tuple.valid) } var ruleChange = false @@ -125,14 +133,14 @@ import MVMCore //get the fieldKey for the effect if let effected = fields[effect.fieldKey] { //get the validity - let validity = effect.validate(fields) + let effectTuple = effect.validate(fields) //set the effect with the validation - effect.setEffect(validity: validity, field: effected, form: self, group: group) + effect.setEffect(validity: effectTuple.valid, field: effected, form: self, group: group) //update the group form rules if let ruleIds = effect.activatedRuleIds { - let didChange = self.updateRules(for: group, with: validity, for: effect.fieldKey, and: ruleIds) + let didChange = self.updateRules(for: group, with: effectTuple.valid, for: effect.fieldKey, and: ruleIds) if(didChange) { ruleChange = didChange } @@ -147,7 +155,7 @@ import MVMCore return try self.validateGroup(group, counter: counter + 1) } } else { - return valid + return tuple.valid } }