Skip to content

Commit

Permalink
Add FormValidation.errorsDescription() to get a description for all e…
Browse files Browse the repository at this point in the history
…rrrors messages separated with new line
  • Loading branch information
MalekKamel committed Aug 14, 2022
1 parent 23168e8 commit 60c932e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Sources/FormValidation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ public class FormValidation: ObservableObject {
}
return isAllValid()
}

public func errorsDescription() -> String {
guard !validationMessages.isEmpty else {
return ""
}
return validationMessages.reduce("") { partialResult, s in
if partialResult.isEmpty {
return s
}
return "\(partialResult)\n\(s)"
}
}
}

public extension FormValidation {
Expand Down

0 comments on commit 60c932e

Please sign in to comment.