Accept Image in Filefield ExtJs
Asked Answered
F

1

2

I have a filefield componente in my application and I want to restrict it to only image files. I've found this question on stackoverflow:

How to restrict file type using xtype filefield(extjs 4.1.0)?

Add accept="image/*" attribute to input field in ExtJs

I'm using this code:

{
  xtype:'filefield',
  listeners:{
    afterrender:function(cmp){
      cmp.fileInputEl.set({
        accept:'audio/*'
      });
    }
  }
}

But this code only works the first time I click on "Examine" button, when I click again on it, the restriction dissapears. I've been looking for other events like onclick to write this code in that event, but I don't find the best way to do it, Anyone has any idea?

Greetings.

Faruq answered 21/3, 2014 at 9:18 Comment(0)
M
0

This is happening because when you submit form, it calls Ext.form.field.File#reset(). You should override reset() method like this, to keep you accept property:

{
        xtype:'filefield',
        reset: function () {  
          var me = this,                                                                
            clear = me.clearOnSubmit;
         if (me.rendered) {   
            me.button.reset(clear);
            me.fileInputEl = me.button.fileInputEl;
            me.fileInputEl.set({
               accept: 'audio/*'    
            });
            if (clear) {
               me.inputEl.dom.value = '';
            }
            me.callParent();
        }},
        listeners:{
           afterrender:function(cmp){
              cmp.fileInputEl.set({
                  accept:'audio/*'
              });
           }
        }
}
Million answered 24/9, 2014 at 12:55 Comment(1)
There is a } missing to close the reset method.Cuevas

© 2022 - 2024 — McMap. All rights reserved.