View Full Version : Textbox maxlength attribute behavior
majain
19 Oct 2008, 6:05 AM
In HTML, the maxlength attribute of a Textbox prevents user from typing texts greater than what is specified by maxlength attribute.
However, GXT's TextField.setMaxLength(...) method is used for max length validation only. It does not prevent user from typing texts greater than max length.
Is there any HTML maxlength equivalent attribute exist in GXT's TextField widget?
Thanks,
Majain
majain
20 Oct 2008, 5:14 PM
Anyone has idea on how to set the maxlength html (prevent user from typing more than the length specified) attribute on TextField widget?
mjlecomte
20 Oct 2008, 5:25 PM
There's probably some additional configuration you need to do if this is similar to ExtJS. Search ExtJS forums and you'll find something.
fieldLabel: 'First Name',
id: 'firstname',
name: 'FirstName',
//use autoCreate so the maxlength setting for form textfield and
//numberfield components respected on onkeyup/onkeydown, rather
//than just when the form is submitted.
autoCreate : {
tag : 'input',
type : 'text',
name : 'FirstName',
//if don't specify this in autoCreate then just specifies size="6"
maxlength : 6
},
eldontc
13 Nov 2008, 10:08 AM
Majain,
I have the same problem! Anyone have a suggest?
This is the basic function for a GUI framework.
Eldon
Nandez
16 Dec 2008, 6:59 AM
Hello, any solution for that problem?
Thanks.
Hello,
this is really easy to implement:
TextField<String> text = new TextField() {
@Override
public void setMaxLength(int m) {
super.setMaxLength(m);
if (rendered) {
getInputEl().setElementAttribute("maxLength", m);
}
}
@Override
protected void onRender(Element parent, int index) {
super.onRender(parent, index);
getInputEl().setElementAttribute("maxLength", getMaxLength());
}
};
Sven
Nandez
16 Dec 2008, 7:33 AM
Thanks for your quick response.
Joshua093
2 Feb 2012, 9:52 AM
We have been using this code faithfully with our TextFields, but recently we've needed to implement this same logic with a text area and no matter what I try it doesn't work. Any quick solutions??
Powered by vBulletin® Version 4.1.5 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.