colors on text fields get cleared afterwards

This commit is contained in:
Cameron McCord 2015-05-05 19:21:31 -06:00
parent 847885a490
commit afc15b0aa4
2 changed files with 17 additions and 0 deletions

View File

@ -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)
}
}
}
}

View File

@ -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")
}
}
}