File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,7 @@ open class FormInput: UITextField {
32
32
open var formInputDelegate : FormInputDelegate !
33
33
fileprivate var inputAccessory : UIView !
34
34
fileprivate var validationHandler : ValidatedFormInput !
35
+ fileprivate var limit : Int !
35
36
open var validationDelegate : ValidatedFormInputDelegate !
36
37
open var validationDataSource : ValidatedFormInputDataSource !
37
38
@@ -61,6 +62,13 @@ open class FormInput: UITextField {
61
62
}
62
63
63
64
// MARK: Public own methods
65
+
66
+ /**
67
+ Applies a custom char limit to the field
68
+ */
69
+ open func setCustomCharLimit( limit: Int ? ) {
70
+ self . limit = limit
71
+ }
64
72
65
73
/**
66
74
Stops the current edition.
@@ -94,5 +102,13 @@ extension FormInput: UITextFieldDelegate {
94
102
95
103
return true ;
96
104
}
105
+
106
+ public func textField( _ textField: UITextField , shouldChangeCharactersIn range: NSRange , replacementString string: String ) -> Bool {
107
+ if let _ = limit {
108
+ return textField. text!. characters. count < limit
109
+ }
110
+
111
+ return true
112
+ }
97
113
}
98
114
You can’t perform that action at this time.
0 commit comments