extjs filefield java_如何使用xtype filefield(extjs 4.1.0)限制文件類型?

  • Post author:
  • Post category:java


I am trying to implement file upload feature using extjs 4.1.0. Whereas I want to restrict users to select only image files(jpg,png,gif). Is there any filter which can be applied so that users will only be able to see and then select the types of the files mentioned above?

我正在嘗試使用extjs 4.1.0實現文件上傳功能。而我想限制用戶只選擇圖像文件(jpg、png、gif)。是否有可以應用的過濾器,以便用戶只能看到並選擇上面提到的文件的類型?

3 个解决方案

#1

2

See http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.VTypes VAlidation types for an example of a custom type. You could use a regexp to specify alphaMask as well.

有關自定義類型的示例,請參見http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.VTypes驗證類型。您也可以使用regexp來指定alphaMask。

#2

6

You could stuff like this as well :

你也可以像這樣:

{

xtype: ‘filefield’,

buttonText: ‘….’,

listeners:{

afterrender:function(cmp){

cmp.fileInputEl.set({

accept:’image/*’ // or w/e type

});

}

}

}

#3

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’

}

regex adds client side validation, to which a form bind can be put on whatever form or action you are planning on doing.

regex添加了客戶端驗證,可以將表單綁定放在計划要執行的任何表單或操作上。



版权声明:本文为weixin_39831242原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。