Including new TextField property, which allows to specifying the maximum length of the text
Workaround
Android
textfieldloaded(args){
var textfield = args.object;
var legth = parseInt(this.maxvalue);
var array = [];
array[0] = new android.text.InputFilter.LengthFilter(legth);
textfield .android.setFilters(array);
}
iOS
textfieldloaded(args){
var textfield = args.object;
var legth = parseInt(this.maxvalue);
var uiTextView = textfield .ios;
let tf = <any>this.textField;
var newWeakRef = new WeakRef(uiTextView);
let newDelegate = newUITextFieldDelegateImpl.initWithOriginalDelegate(tf._delegate, legth);
uiTextView.delegate = newDelegate;
}
class newUITextFieldDelegateImpl extends NSObject implements UITextFieldDelegate {
public static ObjCProtocols = [UITextFieldDelegate];
private _originalDelegate: UITextFieldDelegate;
private firstEdit: boolean;
private maxlegth:number
public static initWithOriginalDelegate(originalDelegate: UITextFieldDelegate, maxl:number): newUITextFieldDelegateImpl {
console.log("initWithOwner")
let delegate = <newUITextFieldDelegateImpl>newUITextFieldDelegateImpl.new();
delegate._originalDelegate = originalDelegate;
delegate.maxlegth=maxl;
return delegate;
}
public textFieldShouldBeginEditing(textField: UITextField): boolean {
return this._originalDelegate.textFieldShouldBeginEditing(textField);
}
public textFieldDidEndEditing(textField: UITextField) {
return this._originalDelegate.textFieldDidEndEditing(textField);
}
public textFieldShouldClear(textField: UITextField) {
return this._originalDelegate.textFieldShouldClear(textField);
}
public textFieldShouldReturn(textField: UITextField): boolean {
return this._originalDelegate.textFieldShouldReturn(textField);
}
public textFieldShouldChangeCharactersInRangeReplacementString(textField: UITextField, range: NSRange, replacementString: string): boolean {
if ((this.maxlegth <= textField.text.length)&&(replacementString.length > range.length)) {
return false;
}
return this._originalDelegate.textFieldShouldChangeCharactersInRangeReplacementString(textField, range, replacementString);
}
}
Including new TextField property, which allows to specifying the maximum length of the text
Workaround
Android
iOS