From afc15b0aa47d8e0a50ae93aa7c3874680a954ac4 Mon Sep 17 00:00:00 2001 From: Cameron McCord Date: Tue, 5 May 2015 19:21:31 -0600 Subject: [PATCH] colors on text fields get cleared afterwards --- Validator/Validator.swift | 11 +++++++++++ ValidatorTests/ValidatorTests.swift | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/Validator/Validator.swift b/Validator/Validator.swift index a92d19a..809dda4 100644 --- a/Validator/Validator.swift +++ b/Validator/Validator.swift @@ -42,6 +42,11 @@ public class Validator { field.layer.borderWidth = 1.0 } + private func unmarkTextFieldAsInError(field:UITextField) { + field.layer.borderColor = UIColor.clearColor().CGColor + field.layer.borderWidth = 0.0 + } + public func validate(delegate:ValidationDelegate) { for field in validations.keys { @@ -59,6 +64,9 @@ public class Validator { if let errorLabel = currentRule.errorLabel { errorLabel.text = nil } + if shouldMarkTextFieldsInError { + self.unmarkTextFieldAsInError(field) + } } } } @@ -87,6 +95,9 @@ public class Validator { if let errorLabel = currentRule.errorLabel { errorLabel.text = nil } + if shouldMarkTextFieldsInError { + self.unmarkTextFieldAsInError(field) + } } } } diff --git a/ValidatorTests/ValidatorTests.swift b/ValidatorTests/ValidatorTests.swift index 4a1879d..0692946 100644 --- a/ValidatorTests/ValidatorTests.swift +++ b/ValidatorTests/ValidatorTests.swift @@ -260,6 +260,12 @@ class ValidatorTests: XCTestCase { REGISTER_VALIDATOR.validate { (errors) -> Void in XCTAssert(errors.count == 1, "Should come back with errors") XCTAssert(CGColorEqualToColor(self.REGISTER_TXT_FIELD.layer.borderColor, UIColor.redColor().CGColor), "Color should be what it was set as") + + self.REGISTER_TXT_FIELD.text = self.VALID_EMAIL + self.REGISTER_VALIDATOR.validate { (errors) -> Void in + XCTAssert(errors.count == 0, "Should come back without errors") + XCTAssert(!CGColorEqualToColor(self.REGISTER_TXT_FIELD.layer.borderColor, UIColor.redColor().CGColor), "Color should be what it was set as") + } } }