-
8 Sep 2010 5:47 AM #1
Error when trying to limit the length of a TextField
Error when trying to limit the length of a TextField
Hi,
In my application I have some TextFields for which I want to limit the number of characters the user can type in each of them.
To do this, I tried to create my own Component which extend the GXT TextField. In my component, I override the setMaxLength method like that :
In my application, I call the setMaxlength() method when I create the user interface. The problem is that, when I launch my application, I have the following error message :PHP Code:@Override
public void setMaxLength(int maxLength) {
super.setMaxLength(maxLength);
super.getInputEl().setElementAttribute("maxlength", maxlength);
}
"java.lang.AssertionError: Method must be called after the component is rendered".
Why ?
How can I limit the size of number of characters the user can enter in my TextField ?
Thanks,
-
8 Sep 2010 5:51 AM #2
As the exception tells you, you can only call getInputEl() after rendering the field.
-
8 Sep 2010 6:00 AM #3
This code is untestedCode:@Override public void setMaxLength(int maxLength) { super.setMaxLength(maxLength); if(isRendered()){ getInputEl().setElementAttribute("maxlength", maxlength); } } @Override protected void onRender(Element target, int index) { super.onRender(target, index); setMaxLength(getMaxLength()); }
-
8 Sep 2010 6:38 AM #4
-
8 Sep 2010 6:42 AM #5
-
13 Jan 2011 6:43 AM #6
Works on Firefox 3.6, but not IE8
Using IE Developer Tools I see maxlegnth is set on input tag, but it lets me keep on typing.
...any idea?
-
14 Jan 2011 12:35 AM #7
Have you tried using this line :
instead ofCode:if(isRendered()){ getInputEl().setElementAttribute("maxLength", maxLength); }
Code:if(isRendered()){ getInputEl().setElementAttribute("maxlength", maxlength); }
-
21 Feb 2012 6:13 AM #8
Facing same problem.
Facing same problem.
Facing same issue. Not working in IE. Any working suggestions??
Similar Threads
-
Ext.Ajax.request -- params length limit?
By enso491 in forum Ext 3.x: Help & DiscussionReplies: 1Last Post: 18 Feb 2010, 4:02 PM -
tbar - textfield dynamic length
By heidtmare in forum Ext 3.x: Help & DiscussionReplies: 2Last Post: 15 Jun 2009, 1:35 PM -
Limit on JsonStore data length for ComboBox?
By cbg3 in forum Ext 2.x: Help & DiscussionReplies: 4Last Post: 10 Dec 2008, 5:13 AM -
feature request - length / line limit function on textarea
By mystix in forum Ext 2.x: Help & DiscussionReplies: 2Last Post: 13 Mar 2007, 7:54 AM


Reply With Quote