Results 1 to 8 of 8

Thread: Textbox maxlength attribute behavior

  1. #1

    Default 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

    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

    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

    Default

    Majain,

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

    Eldon

  5. #5

    Default

    Hello, any solution for that problem?

    Thanks.

  6. #6
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    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

    Default

    Thanks for your quick response.

  8. #8
    Sencha User
    Join Date
    May 2011
    Location
    Illinois
    Posts
    32

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •