OR Validation
Closed this issue · 2 comments
TiPunch69 commented
Is there any way to create an OR validation (enter field A or field B). Currently all validators are AND conjunctions.
MalekKamel commented
Hey, thanks for asking the question.
You can use disableValidation
closure for applying you logic as below:
@DateFormField(message: "Date can not be in the future!")
var birthday: Date = Date()
lazy var birthdayValidation = _birthday.validation(
manager: manager,
before: Date(),
disableValidation: {
// You can add logic here to disable this field validation. If you return true, the field will be always valid
// and the validation will be ignored.
// This is useful when you need to apply OR validation (enter field A or field B).
false
})
I have updated the example https://github.com/Open-Bytes/SwiftUIFormValidator/blob/master/Example/ExampleForm.swift.
TiPunch69 commented
Super, thanks. That was exactly what I needed. Could you also add this to the documentation plz for other people?