diff --git a/Validator/Validator.swift b/Validator/Validator.swift index 718d23d..73c09c0 100644 --- a/Validator/Validator.swift +++ b/Validator/Validator.swift @@ -18,7 +18,7 @@ public class Validator { // dictionary to handle complex view hierarchies like dynamic tableview cells public var errors:[UITextField:ValidationError] = [:] public var validations:[UITextField:ValidationRule] = [:] - public var markTextFieldsInError:Bool = false + public var shouldMarkTextFieldsInError:Bool = false public var textFieldErrorColor:UIColor = UIColor.redColor() public init(){} @@ -51,7 +51,7 @@ public class Validator { if let errorLabel = currentRule.errorLabel { errorLabel.text = error.errorMessage } - if markTextFieldsInError { + if shouldMarkTextFieldsInError { self.markTextFieldAsInError(field) } errors[field] = error @@ -79,7 +79,7 @@ public class Validator { if let errorLabel = currentRule.errorLabel { errorLabel.text = error.errorMessage } - if markTextFieldsInError { + if shouldMarkTextFieldsInError { self.markTextFieldAsInError(field) } errors[field] = error diff --git a/ValidatorTests/ValidatorTests.swift b/ValidatorTests/ValidatorTests.swift index 4906c51..020564f 100644 --- a/ValidatorTests/ValidatorTests.swift +++ b/ValidatorTests/ValidatorTests.swift @@ -44,6 +44,8 @@ class ValidatorTests: XCTestCase { let ERROR_LABEL = UILabel() + let GREEN_COLOR = UIColor.greenColor() + override func setUp() { super.setUp() // Put setup code here. This method is called before the invocation of each test method in the class. @@ -238,4 +240,15 @@ class ValidatorTests: XCTestCase { } } } + + func testTextFieldBorderColorSet() { + REGISTER_VALIDATOR.registerField(REGISTER_TXT_FIELD, errorLabel: ERROR_LABEL, rules: [EmailRule()]) + REGISTER_TXT_FIELD.text = INVALID_EMAIL + REGISTER_VALIDATOR.textFieldErrorColor = GREEN_COLOR + REGISTER_VALIDATOR.shouldMarkTextFieldsInError = true + REGISTER_VALIDATOR.validate { (errors) -> Void in + XCTAssert(errors.count == 1, "Should come back with errors") + XCTAssert(CGColorEqualToColor(self.REGISTER_TXT_FIELD.layer.borderColor, self.GREEN_COLOR.CGColor), "Color should be what it was set as") + } + } }