在Filefield ExtJ中接受图像 [英] Accept Image in Filefield ExtJs
问题描述
我的应用程序中有一个文件框组件,我想将其限制为仅图像文件。我在stackoverflow上发现了这个问题:
Add accept =image / *属性到ExtJs中的输入字段
我使用这段代码:
{
xtype:'filefield',
listeners:{
afterrender:function(cmp){
cmp.fileInputEl.set({
接受:'audio / *'
});
}
}
}
但是这个代码只能工作第一次点击检查按钮,当我再次点击它时,限制消失。我一直在寻找其他事件,例如 onclick
在该事件中编写此代码,但是我没有找到最好的方法,任何人都有想法? / p>
问候。
发生这种情况是因为提交表单时,它调用 Ext.form.field.File#reset()
。
您应该覆盖这样的reset()方法,以保持接受属性:
{
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 / *'
});
}
}
}
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.
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/*'
});
}
}
}
这篇关于在Filefield ExtJ中接受图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!