Commit f5ea7a80 by Orkhan Alikhanov

Changed `autoValidateOnlyIfErrorIsShownOnce` flag to AutoValidationType case

parent e34e5031
...@@ -15,7 +15,6 @@ open class ErrorTextFieldValidator { ...@@ -15,7 +15,6 @@ open class ErrorTextFieldValidator {
open weak var textField: ErrorTextField? open weak var textField: ErrorTextField?
open var autoValidationType: AutoValidationType = .default open var autoValidationType: AutoValidationType = .default
open var autoValidateOnlyIfErrorIsShownOnce = true
open var isErrorShownOnce = false open var isErrorShownOnce = false
public init(textField: ErrorTextField) { public init(textField: ErrorTextField) {
...@@ -30,14 +29,16 @@ open class ErrorTextFieldValidator { ...@@ -30,14 +29,16 @@ open class ErrorTextFieldValidator {
@objc @objc
private func checkIfErrorHasGone() { private func checkIfErrorHasGone() {
guard let textField = textField else { return } guard let textField = textField else { return }
if autoValidateOnlyIfErrorIsShownOnce && !isErrorShownOnce { return }
switch autoValidationType { switch autoValidationType {
case .none: break case .none: break
case .custom(let closure): case .custom(let closure):
closure(textField) closure(textField)
case .default: case .default:
textField.isValid() guard isErrorShownOnce else { return }
textField.isValid()
case .always:
textField.isValid()
} }
} }
...@@ -67,6 +68,7 @@ open class ErrorTextFieldValidator { ...@@ -67,6 +68,7 @@ open class ErrorTextFieldValidator {
public enum AutoValidationType { public enum AutoValidationType {
case none case none
case `default` case `default`
case always
case custom((ErrorTextField) -> Void) case custom((ErrorTextField) -> Void)
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment