目录
目录README.md

FormView


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.

关于
97.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

©Copyright 2023 CCF 开源发展委员会
Powered by Trustie& IntelliDE 京ICP备13000930号