Accept Image in Filefield ExtJs

久未见 提交于 2019-12-24 01:50:19

问题


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.


回答1:


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/*'
              });
           }
        }
}


来源:https://stackoverflow.com/questions/22554621/accept-image-in-filefield-extjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!