Skip to content

Commit afc15b0

Browse files
colors on text fields get cleared afterwards
1 parent 847885a commit afc15b0

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

Validator/Validator.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public class Validator {
4242
field.layer.borderWidth = 1.0
4343
}
4444

45+
private func unmarkTextFieldAsInError(field:UITextField) {
46+
field.layer.borderColor = UIColor.clearColor().CGColor
47+
field.layer.borderWidth = 0.0
48+
}
49+
4550
public func validate(delegate:ValidationDelegate) {
4651

4752
for field in validations.keys {
@@ -59,6 +64,9 @@ public class Validator {
5964
if let errorLabel = currentRule.errorLabel {
6065
errorLabel.text = nil
6166
}
67+
if shouldMarkTextFieldsInError {
68+
self.unmarkTextFieldAsInError(field)
69+
}
6270
}
6371
}
6472
}
@@ -87,6 +95,9 @@ public class Validator {
8795
if let errorLabel = currentRule.errorLabel {
8896
errorLabel.text = nil
8997
}
98+
if shouldMarkTextFieldsInError {
99+
self.unmarkTextFieldAsInError(field)
100+
}
90101
}
91102
}
92103
}

ValidatorTests/ValidatorTests.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ class ValidatorTests: XCTestCase {
260260
REGISTER_VALIDATOR.validate { (errors) -> Void in
261261
XCTAssert(errors.count == 1, "Should come back with errors")
262262
XCTAssert(CGColorEqualToColor(self.REGISTER_TXT_FIELD.layer.borderColor, UIColor.redColor().CGColor), "Color should be what it was set as")
263+
264+
self.REGISTER_TXT_FIELD.text = self.VALID_EMAIL
265+
self.REGISTER_VALIDATOR.validate { (errors) -> Void in
266+
XCTAssert(errors.count == 0, "Should come back without errors")
267+
XCTAssert(!CGColorEqualToColor(self.REGISTER_TXT_FIELD.layer.borderColor, UIColor.redColor().CGColor), "Color should be what it was set as")
268+
}
263269
}
264270
}
265271

0 commit comments

Comments
 (0)