An easy-to-use SwiftUI library for working with a group of TextFields.
Features
- Automatic transition between TextFields upon submission
- Validation of TextFields based on specified rules
- Prevention of incorrect input based on specified rules
Usage
struct ContentView: View {
@State var email: String = ""
@State var phone: String = ""
@State var emailFailedRules: [TextValidationRule] = []
var body: some View {
FormView {
ScrollView(.vertical) {
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.
You can also use a .formView()
modifier instead of FormView
:
ScrollView(.vertical) {
...
}
.formView()
Example Project
ExampleApp provides several more interesting use cases of FormView.
Installation
Swift Package Manager
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"),
]
License
FormView is released under the MIT license. See LICENSE for details.
FormView
An easy-to-use SwiftUI library for working with a group of TextFields.
Features
Usage
ValidationRules
are used for automatic validation of text during input. All rules that have not passed the validation come with thefailedValidationRules
.InputRules
are used to prevent incorrect input.You can also use a
.formView()
modifier instead ofFormView
:Example Project
ExampleApp provides several more interesting use cases of FormView.
Installation
Swift Package Manager
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, typeThen proceed with installation.
You can add FormView as a dependency to the
dependencies
value of yourPackage.swift
:License
FormView is released under the MIT license. See LICENSE for details.