1. #1
    Ext User
    Join Date
    Apr 2008
    Posts
    30
    Vote Rating
    0
    majain is on a distinguished road

      0  

    Default Textbox maxlength attribute behavior

    Textbox maxlength attribute behavior


    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


  2. #2
    Ext User
    Join Date
    Apr 2008
    Posts
    30
    Vote Rating
    0
    majain is on a distinguished road

      0  

    Default


    Anyone has idea on how to set the maxlength html (prevent user from typing more than the length specified) attribute on TextField widget?

  3. #3
    Ext User
    Join Date
    Jul 2007
    Location
    Florida
    Posts
    9,996
    Vote Rating
    6
    mjlecomte will become famous soon enough mjlecomte will become famous soon enough

      0  

    Default


    There's probably some additional configuration you need to do if this is similar to ExtJS. Search ExtJS forums and you'll find something.

    PHP Code:
                    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
                    
    }, 

  4. #4
    Ext User
    Join Date
    Nov 2008
    Posts
    5
    Vote Rating
    0
    eldontc is on a distinguished road

      0  

    Default


    Majain,

    I have the same problem! Anyone have a suggest?
    This is the basic function for a GUI framework.

    Eldon

  5. #5
    Ext User
    Join Date
    May 2008
    Posts
    4
    Vote Rating
    0
    Nandez is on a distinguished road

      0  

    Default


    Hello, any solution for that problem?

    Thanks.

  6. #6
    Sencha User
    Join Date
    Sep 2007
    Posts
    13,971
    Vote Rating
    132
    sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light sven is a glorious beacon of light

      0  

    Default


    Hello,

    this is really easy to implement:

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

  7. #7
    Ext User
    Join Date
    May 2008
    Posts
    4
    Vote Rating
    0
    Nandez is on a distinguished road

      0  

    Default


    Thanks for your quick response.

  8. #8
    Sencha User
    Join Date
    May 2011
    Location
    Illinois
    Posts
    32
    Vote Rating
    0
    Joshua093 is on a distinguished road

      0  

    Default


    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??