最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Extjs reset filefield input - Stack Overflow

programmeradmin3浏览0评论

How reset filefield input in ExtJS? I am trying:

//this - point on Ext.panel.Form

var form = this.getForm();
form.reset();

var filefield = this.getForm().getFields().get(0);
filefield.reset();

filefield.setValue('');

filefield.value = '';

But not one of these methods don't work. Thank you for help!

How reset filefield input in ExtJS? I am trying:

//this - point on Ext.panel.Form

var form = this.getForm();
form.reset();

var filefield = this.getForm().getFields().get(0);
filefield.reset();

filefield.setValue('');

filefield.value = '';

But not one of these methods don't work. Thank you for help!

Share Improve this question asked Jun 20, 2012 at 11:53 vedmedvedmed 3552 gold badges8 silver badges16 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

Use below code will help you

function clearFileUpload(id){
    // get the file upload element
    fileField     = document.getElementById(id);
    // get the file upload parent element
    parentNod     = fileField.parentNode;
    // create new element
    tmpForm        = document.createElement("form");
    parentNod.replaceChild(tmpForm,fileField);
    tmpForm.appendChild(fileField);
    tmpForm.reset();
    parentNod.replaceChild(fileField,tmpForm);
}

Old post, but I encountered this problem as well, and I found a cleaner solution.

First of all make sure , the filefield has allowBlank: true set.

Then you can call the setRawValue method as so :

    filefield.setRawValue("");

The easiest way that you might be looking for would be :

filefield.fileInputEl.dom.value = '';

Based on this answer: HTML input file selection event not firing upon selecting the same file

In Ext.ux.form.FileUploadField ponent add the following code in the change event under the bindListeners function.

var that = this;
setTimeout(function() {
    that.fileInput.dom.value = null;
    that.setValue(that.fileInput.dom.value);
}, 100);      

bindListeners: function(){
  this.fileInput.on({
    scope: this,
    mouseenter: function() {
      this.button.addClass(['x-btn-over','x-btn-focus'])
    },
    mouseleave: function(){
      this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
    },
    mousedown: function(){
      this.button.addClass('x-btn-click')
    },
    mouseup: function(){
      this.button.removeClass(['x-btn-over','x-btn-focus','x-btn-click'])
    },
    change: function(){
      var v = this.fileInput.dom.value;
      this.setValue(v);
      this.fireEvent('fileselected', this, v);

      var that = this;
      setTimeout(function() {
        that.fileInput.dom.value = null;
        that.setValue(that.fileInput.dom.value);
      }, 100);
    }
  }); 
},

发布评论

评论列表(0)

  1. 暂无评论