Search code examples
extjsextjs6-classic

Change maxLength dynamically in textarea ExtJS


I want to change maxLength for textarea dynamically. I tried this:

{
        xtype: 'textareafield',

        msgTarget: 'under',
        fieldLabel: __('text_sms'),            
        maxLength: 60,
        name: 'text-sms',
        bind: {
            value: __('sms_text_template'),
            afterSubTpl: '<span>{length}/{maxLength}</span>'
        },

        listeners: {
            change: function (el) {
                el.setMaxLength(60); // error is not a function
            }
        }

}

And also I tried to bind value maxLength:

 bind: {
            value: __('sms_text_template'),
            maxLength: '{maxLength}'
        },

Solution

  • You need to define getter and setter to textarea and after this you're free to call them: FIDDLE

    EDIT:
    This is how you do it with binding: FIDDLE
    maxLength isn't bindable, so to make it, you need getter & setter and after this you can change them from viewmodel.