Skip to content

Commit ffe902d

Browse files
committed
fix issue with errors showing up for unregistered fields
1 parent 34eced2 commit ffe902d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

Validator/Validator.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class Validator {
3333

3434
public func unregisterField(textField:UITextField) {
3535
validations.removeValueForKey(textField)
36+
errors.removeValueForKey(textField)
3637
}
3738

3839
public func validate(delegate:ValidationDelegate) {

ValidatorTests/ValidatorTests.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class ValidatorTests: XCTestCase {
3939
let UNREGISTER_VALIDATOR = Validator()
4040
let UNREGISTER_RULES = [Rule]()
4141

42+
let UNREGISTER_ERRORS_TXT_FIELD = UITextField()
43+
let UNREGISTER_ERRORS_VALIDATOR = Validator()
44+
4245
override func setUp() {
4346
super.setUp()
4447
// Put setup code here. This method is called before the invocation of each test method in the class.
@@ -165,6 +168,18 @@ class ValidatorTests: XCTestCase {
165168
XCTAssert(UNREGISTER_VALIDATOR.validations[UNREGISTER_TXT_FIELD] == nil, "Textfield should unregister")
166169
}
167170

171+
func testUnregisterError(){
172+
UNREGISTER_ERRORS_VALIDATOR.registerField(UNREGISTER_ERRORS_TXT_FIELD, rules: [EmailRule()])
173+
UNREGISTER_ERRORS_TXT_FIELD.text = INVALID_EMAIL
174+
UNREGISTER_ERRORS_VALIDATOR.validate { (errors) -> Void in
175+
XCTAssert(errors.count == 1, "Should come back with errors")
176+
}
177+
UNREGISTER_ERRORS_VALIDATOR.unregisterField(UNREGISTER_ERRORS_TXT_FIELD)
178+
UNREGISTER_ERRORS_VALIDATOR.validate { (errors) -> Void in
179+
XCTAssert(errors.count == 0, "Should not come back with errors")
180+
}
181+
}
182+
168183
// MARK: Validate Functions
169184

170185
func testValidateWithCallback() {

0 commit comments

Comments
 (0)