1. #1
    Sencha User
    Join Date
    Feb 2010
    Posts
    39
    Vote Rating
    0
    ales is on a distinguished road

      0  

    Default 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 :

    PHP Code:
    @Override
        
    public void setMaxLength(int maxLength) {
            
    super.setMaxLength(maxLength);
            
    super.getInputEl().setElementAttribute("maxlength"maxlength);
        } 
    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 :
    "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,

  2. #2
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,716
    Vote Rating
    107
    sven is just really nice sven is just really nice sven is just really nice sven is just really nice

      0  

    Default


    As the exception tells you, you can only call getInputEl() after rendering the field.

  3. #3
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,716
    Vote Rating
    107
    sven is just really nice sven is just really nice sven is just really nice sven is just really nice

      0  

    Default


    Code:
    @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());
    }
    This code is untested

  4. #4
    Sencha User
    Join Date
    Feb 2010
    Posts
    39
    Vote Rating
    0
    ales is on a distinguished road

      0  

    Default


    Thanks, this code works fine.

  5. #5
    Software Architect
    Join Date
    Sep 2007
    Posts
    13,716
    Vote Rating
    107
    sven is just really nice sven is just really nice sven is just really nice sven is just really nice

      0  

    Default


    Great, good to know.

  6. #6
    Sencha User
    Join Date
    Aug 2009
    Posts
    89
    Vote Rating
    1
    r4nd7263 is on a distinguished road

      0  

    Default


    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?

  7. #7
    Sencha User
    Join Date
    Feb 2010
    Posts
    39
    Vote Rating
    0
    ales is on a distinguished road

      0  

    Default


    Have you tried using this line :

    Code:
    if(isRendered()){
          getInputEl().setElementAttribute("maxLength", maxLength);
    }
    instead of
    Code:
    if(isRendered()){
            getInputEl().setElementAttribute("maxlength", maxlength);
    }

  8. #8
    Sencha User
    Join Date
    Feb 2012
    Posts
    2
    Vote Rating
    0
    syamlal is on a distinguished road

      0  

    Default Facing same problem.

    Facing same problem.


    Facing same issue. Not working in IE. Any working suggestions??

Similar Threads

  1. Ext.Ajax.request -- params length limit?
    By enso491 in forum Ext 3.x: Help & Discussion
    Replies: 1
    Last Post: 18 Feb 2010, 4:02 PM
  2. tbar - textfield dynamic length
    By heidtmare in forum Ext 3.x: Help & Discussion
    Replies: 2
    Last Post: 15 Jun 2009, 1:35 PM
  3. Limit on JsonStore data length for ComboBox?
    By cbg3 in forum Ext 2.x: Help & Discussion
    Replies: 4
    Last Post: 10 Dec 2008, 5:13 AM
  4. feature request - length / line limit function on textarea
    By mystix in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 13 Mar 2007, 7:54 AM