8

I want to add client side validation for file upload using HTML5 "accept" attribute and ExtJs "inputAttrTpl" config. My ExtJs code is following (ExtJs 4.1):

{
              xtype : 'filefield',
              action : 'upload',
              name : 'file',
              inputAttrTpl: 'accept="image/*"',
              hideLabel : true,
              buttonOnly : true,
              anchor : '100%',
              buttonText : 'Upload img...',
              margin: 5
}

But when I am checking file field in firebug, it doesn't contain "accept" attribute. Can you suggest some solutions for this issue? Thanks for your replies.

4

2 回答 2

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

您可以将接受设置为“”以删除限制。

小提琴

于 2013-04-28T19:38:45.097 回答
0
{
        xtype: 'fileuploadfield',
        name: 'file',
        fieldLabel: 'Photo',
        labelWidth: 50,
        allowBlank: false,
        buttonText: 'SelectPhoto',
        anchor: '100%',
        reset: function () {
            var me = this,
                clear = me.clearOnSubmit;
            if (me.rendered) {
                me.button.reset(clear);
                me.fileInputEl = me.button.fileInputEl;
                me.fileInputEl.set({
                    accept: 'image/*'
                });
                if (clear) {
                    me.inputEl.dom.value = '';
                }
                me.callParent();
            }},
        listeners:{
            change: 'fileInputChange',
            afterrender:function(cmp){
                cmp.fileInputEl.set({
                    accept:'image/*'
                });
            }
        },
        regex: /(.)+((\.png)|(\.jpg)|(\.jpeg)(\w)?)$/i,
        regexText: 'Only PNG and JPEG image formats are accepted'
    }
于 2015-04-06T23:49:16.880 回答