@@ -33,6 +33,21 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
3333
3434 self . view. addGestureRecognizer ( UITapGestureRecognizer ( target: self , action: " hideKeyboard " ) )
3535
36+ validator. styleTransformers ( success: { ( validationRule) -> Void in
37+ println ( " here " )
38+ // clear error label
39+ validationRule. errorLabel? . hidden = true
40+ validationRule. textField. layer. borderColor = UIColor . clearColor ( ) . CGColor
41+ validationRule. textField. layer. borderWidth = 0.0
42+
43+ } , error: { ( validationError) -> Void in
44+ println ( " error " )
45+ validationError. errorLabel? . hidden = false
46+ validationError. errorLabel? . text = validationError. errorMessage
47+ validationError. textField. layer. borderColor = UIColor . redColor ( ) . CGColor
48+ validationError. textField. layer. borderWidth = 1.0
49+ } )
50+
3651 validator. registerField ( fullNameTextField, errorLabel: fullNameErrorLabel , rules: [ RequiredRule ( ) , FullNameRule ( ) ] )
3752 validator. registerField ( emailTextField, errorLabel: emailErrorLabel, rules: [ RequiredRule ( ) , EmailRule ( ) ] )
3853 validator. registerField ( emailConfirmTextField, errorLabel: emailConfirmErrorLabel, rules: [ RequiredRule ( ) , ConfirmationRule ( confirmField: emailTextField) ] )
@@ -42,7 +57,7 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
4257
4358 @IBAction func submitTapped( sender: AnyObject ) {
4459 println ( " Validating... " )
45- self . clearErrors ( )
60+ // self.clearErrors()
4661 validator. validate ( self )
4762 }
4863
@@ -58,38 +73,38 @@ class ViewController: UIViewController , ValidationDelegate, UITextFieldDelegate
5873 }
5974 func validationFailed( errors: [ UITextField : ValidationError ] ) {
6075 println ( " Validation FAILED! " )
61- self . setErrors ( )
76+ // self.setErrors()
6277 }
6378
6479 // MARK: Error Styling
6580
66- func removeError( label: UILabel , textField: UITextField ) {
67- label. hidden = true
68- textField. layer. borderWidth = 0.0
69- }
81+ // func removeError(label:UILabel, textField:UITextField) {
82+ // label.hidden = true
83+ // textField.layer.borderWidth = 0.0
84+ // }
7085
71- func removeAllErrors( ) {
72- removeError ( fullNameErrorLabel, textField: fullNameTextField)
73- removeError ( emailErrorLabel, textField: emailTextField)
74- removeError ( phoneNumberErrorLabel, textField: phoneNumberTextField)
75- removeError ( zipcodeErrorLabel, textField: zipcodeTextField)
76- }
86+ // func removeAllErrors(){
87+ // removeError(fullNameErrorLabel, textField: fullNameTextField)
88+ // removeError(emailErrorLabel, textField: emailTextField)
89+ // removeError(phoneNumberErrorLabel, textField: phoneNumberTextField)
90+ // removeError(zipcodeErrorLabel, textField: zipcodeTextField)
91+ // }
7792
78- private func setErrors( ) {
79- for (field, error) in validator. errors {
80- field. layer. borderColor = UIColor . redColor ( ) . CGColor
81- field. layer. borderWidth = 1.0
82- error. errorLabel? . text = error. errorMessage
83- error. errorLabel? . hidden = false
84- }
85- }
93+ // private func setErrors(){
94+ // for (field, error) in validator.errors {
95+ // field.layer.borderColor = UIColor.redColor().CGColor
96+ // field.layer.borderWidth = 1.0
97+ // error.errorLabel?.text = error.errorMessage
98+ // error.errorLabel?.hidden = false
99+ // }
100+ // }
86101
87- private func clearErrors( ) {
88- for (field, error) in validator. errors {
89- field. layer. borderWidth = 0.0
90- error. errorLabel? . hidden = true
91- }
92- }
102+ // private func clearErrors(){
103+ // for (field, error) in validator.errors {
104+ // field.layer.borderWidth = 0.0
105+ // error.errorLabel?.hidden = true
106+ // }
107+ // }
93108
94109 func hideKeyboard( ) {
95110 self . view. endEditing ( true )
0 commit comments