Skip to content

Commit

Permalink
Make isDisplayingValidationErrors based on the validationResults
Browse files Browse the repository at this point in the history
  • Loading branch information
Supereg committed Nov 3, 2023
1 parent bd04a27 commit c961e57
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Sources/SpeziValidation/ValidationEngine.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ public class ValidationEngine: Identifiable {

/// Flag that indicates if ``displayedValidationResults`` returns any ``FailedValidationResult``.
@MainActor public var isDisplayingValidationErrors: Bool {
let gotResults = !validationResults.isEmpty

if configuration.contains(.hideFailedValidationOnEmptySubmit) {
return !inputValid && (source == .manual || !inputWasEmpty)
return gotResults && (source == .manual || !inputWasEmpty)

Check warning on line 62 in Sources/SpeziValidation/ValidationEngine.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziValidation/ValidationEngine.swift#L62

Added line #L62 was not covered by tests
}

return !inputValid
return gotResults
}


Expand Down
4 changes: 4 additions & 0 deletions Sources/SpeziValidation/ValidationModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ struct ValidationModifier<FocusValue: Hashable>: ViewModifier {
.onChange(of: input) {
validation.submit(input: input, debounce: true)
}
.onSubmit(of: .text) {
// here we just make sure that we submit it without a debounce
validation.submit(input: input)
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions Sources/SpeziValidation/Views/VerifiableTextField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ public struct VerifiableTextField<FieldLabel: View, FieldFooter: View>: View {
SecureField(text: $text, label: { label })

Check warning on line 42 in Sources/SpeziValidation/Views/VerifiableTextField.swift

View check run for this annotation

Codecov / codecov/patch

Sources/SpeziValidation/Views/VerifiableTextField.swift#L42

Added line #L42 was not covered by tests
}
}
.onSubmit {
// the validation modifier automatically submits the text,
// here we just make sure that we submit it without a debounce
validationEngine.submit(input: text)
}

HStack {
ValidationResultsView(results: validationEngine.displayedValidationResults)
Expand Down

0 comments on commit c961e57

Please sign in to comment.