An easy-to-use library for working with a group of TextFields.
- Automatic transition between TextFields upon submission
- Validation of TextFields based on specified rules
- Prevention of incorrect input based on specified rules
struct ContentView: View {
@State var email: String = ""
@State var phone: String = ""
@State var emailFailedRules: [TextValidationRule] = []
var body: some View {
FormView {
FormField(
"Email",
text: $email,
validationRules: [.email],
failedValidationRules: $emailFailedRules
)
if emailFailedRules.isEmpty == false {
Text("Email")
.foregroundColor(.red)
}
FormField(
"Phone",
text: $phone,
validationRules: [.digitsOnly],
inputRules: [.digitsOnly]
)
}
}
}
ValidationRules
are used for automatic validation of text during input. All rules that have not passed the validation come with the failedValidationRules
.
InputRules
are used to prevent incorrect input.
ExampleApp provides several more interesting use cases of FormView.
The Swift Package Manager is a tool for automating the distribution of Swift code.
In Xcode 14 or later, select File > Add Packages...
In the search bar, type
https://github.com/maxial/FormView
Then proceed with installation.
You can add FormView as a dependency to the dependencies
value of your Package.swift
:
dependencies: [
.package(url: "https://github.com/maxial/FormView", from: "main"),
]
FormView is released under the MIT license. See LICENSE for details.