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 {
3232 open var formInputDelegate : FormInputDelegate !
3333 fileprivate var inputAccessory : UIView !
3434 fileprivate var validationHandler : ValidatedFormInput !
35+ fileprivate var limit : Int !
3536 open var validationDelegate : ValidatedFormInputDelegate !
3637 open var validationDataSource : ValidatedFormInputDataSource !
3738
@@ -61,6 +62,13 @@ open class FormInput: UITextField {
6162 }
6263
6364 // 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+ }
6472
6573 /**
6674 Stops the current edition.
@@ -94,5 +102,13 @@ extension FormInput: UITextFieldDelegate {
94102
95103 return true ;
96104 }
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+ }
97113}
98114
You can’t perform that action at this time.
0 commit comments