Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ If you need to validate some data, you can use the `Validator` object for this p
import ValidatorCore

let validator = Validator()
let result = validator.validate(input: "text", rule: LengthValidationRule(min: 4, error: "error text"))
let result = validator.validate(input: "text", rule: LengthValidationRule(min: 4, error: "Text must be at least 4 characters long"))

switch result {
case .valid:
print("text is valid")
print("Text is valid")
case let .invalid(errors):
// handle validation errors
print(errors)
print("Validation errors: \(errors.map(\.message))")
}
```

Expand All @@ -66,16 +66,16 @@ class ViewController: UIViewController {
super.viewDidLoad()

/// Adds validation rule to the text field.
textField.add(rule: LengthValidationRule(max: 10, error: "error text"))
textField.add(rule: LengthValidationRule(max: 10, error: "Text must be at most 10 characters"))
/// Enables automatic validation on input change.
textField.validateOnInputChange(isEnabled: true)
/// Handle the validation result.
textField.validationHandler = { result in
switch result {
case .valid:
print("text is valid")
print("Text is valid")
case let .invalid(errors):
print(errors)
print("Validation errors: \(errors)")
}
}
}
Expand Down Expand Up @@ -122,14 +122,14 @@ struct ContentView: View {
@State private var text: String = ""

private let validationRules: [any IValidationRule<String>] = [
LengthValidationRule(max: 10, error: "Text error")
LengthValidationRule(max: 10, error: "Text must be at most 10 characters")
]

var body: some View {
VStack {
TextField("Text", text: $text)
TextField("Enter text", text: $text)
.validate(item: $text, rules: validationRules) { errors in
Text("Text is bigger than 10 characters")
Text("Text exceeds 10 characters")
}
}
}
Expand All @@ -149,10 +149,10 @@ class Form: ObservableObject {
@Published
var manager = FormFieldManager()

@FormField(rules: [LengthValidationRule(max: 20, error: "The first name is very long")])
@FormField(rules: [LengthValidationRule(max: 20, error: "First name is too long")])
var firstName: String = ""

@FormField(rules: [LengthValidationRule(min: 5, error: "The last name is too short")])
@FormField(rules: [LengthValidationRule(min: 5, error: "Last name is too short")])
var lastName: String = ""

lazy var firstNameValidationContainer = _firstName.validate(manager: manager)
Expand Down Expand Up @@ -180,9 +180,9 @@ struct ContentView: View {
form.manager.$isValid,
perform: { value in
if value {
print("The form's fields are valid")
print("All form fields are valid")
} else {
print("The form's fields aren't valid")
print("Some form fields are invalid")
}
}
)
Expand Down