generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate Modifier for Predicates (#42)
# Validate Modifier for Predicates ## ♻️ Current situation & Problem SpeziValidation currently provides the `validate(input:rules:)` modifier to validate `String`-based inputs using SpeziValidation. This PR extends this functionality to `Bool` expressions. The new `validate(_:message:)` modifier can be used to validate all sorts of boolean conditions and supply a validation failure reason with it. ## ⚙️ Release Notes * New `validate(_:message:)` modifier to validate bool expressions. ## 📚 Documentation Documentation was updated to highlight the new modifier. ## ✅ Testing _TBA_ ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
Showing
14 changed files
with
216 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
Tests/UITests/TestApp/ValidationTests/ValidationPredicateTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// | ||
// This source file is part of the Stanford Spezi open-source project | ||
// | ||
// SPDX-FileCopyrightText: 2024 Stanford University and the project authors (see CONTRIBUTORS.md) | ||
// | ||
// SPDX-License-Identifier: MIT | ||
// | ||
|
||
import SpeziValidation | ||
import SwiftUI | ||
|
||
|
||
struct ValidationPredicateTests: View { | ||
enum Selection: String, CaseIterable, Hashable { | ||
case none = "Nothing selected" | ||
case accept = "Accept" | ||
case deny = "Deny" | ||
} | ||
|
||
@State private var selection: Selection = .none | ||
@ValidationState private var validationState | ||
|
||
var body: some View { | ||
List { | ||
VStack(alignment: .leading) { | ||
Picker(selection: $selection) { | ||
ForEach(Selection.allCases, id: \.rawValue) { selection in | ||
Text(selection.rawValue) | ||
.tag(selection) | ||
} | ||
} label: { | ||
Text("Cookies") | ||
} | ||
ValidationResultsView(results: validationState.allDisplayedValidationResults) | ||
} | ||
.validate(selection != .none, message: "This field must be selected.") | ||
.receiveValidation(in: $validationState) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.