@@ -31,6 +31,7 @@ public class ALValidatableTextField: SkyFloatingLabelTextFieldWithIcon {
3131 }
3232 }
3333
34+ public var isValidSuccess : Bool = false
3435
3536 /// Check your free FontAwesome icon in https://fontawesome.com/icons?d=gallery
3637 public var fontAwesomeImage : FontAwesome ? {
@@ -263,18 +264,6 @@ public class ALValidatableTextField: SkyFloatingLabelTextFieldWithIcon {
263264 fontAwesomeStyle = . solid
264265 }
265266
266- func validationFailed( _ errors: [ ( Validatable , ValidationError ) ] ) {
267- // turn the fields to red
268- for (field, error) in errors {
269- if let field = field as? UITextField {
270- field. layer. borderColor = config. errorColor. cgColor
271- field. layer. borderWidth = 1.0
272- }
273- error. errorLabel? . text = error. errorMessage // works if you added labels
274- error. errorLabel? . isHidden = false
275- }
276- }
277-
278267 /// Gets called when editing starts on a paddingNeeded enabled textfield
279268 @objc private func setPaddingForEditingTextFields( ) {
280269 let editingPad = UIEdgeInsets ( top: 8 , left: 0 , bottom: - 8 , right: 0 )
@@ -285,6 +274,27 @@ public class ALValidatableTextField: SkyFloatingLabelTextFieldWithIcon {
285274 private func setPadding( _ padding: UIEdgeInsets = UIEdgeInsets ( top: 4 , left: 0 , bottom: 4 , right: 0 ) ) {
286275 self . padding = padding
287276 }
277+
278+ public func validate( ) {
279+ validator. validate ( self )
280+ }
281+ }
282+
283+ // MARK: - ValidationDelegate
284+ extension ALValidatableTextField : ValidationDelegate {
285+ public func validationSuccessful( ) {
286+ isValidSuccess = true
287+ }
288+
289+ public func validationFailed( _ errors: [ ( Validatable , ValidationError ) ] ) {
290+ // turn the fields to red
291+ isValidSuccess = false
292+ for (field, error) in errors {
293+ if let field = field as? SkyFloatingLabelTextFieldWithIcon {
294+ field. errorMessage = error. errorMessage
295+ }
296+ }
297+ }
288298}
289299
290300// MARK: - TextField Padding
0 commit comments