Сбросить значения после загрузка файла fileuploadfield
Не давно встретил такой баг у компонента fileuploadfield. После загрузка файла нажимаю второй раз отправить данных, а там тоже идёт загрузка файла второй раз. И вот решение этой проблемы:
Ext.override(Ext.form.FileUploadField, { onRender : function(ct, position){ Ext.form.FileUploadField.superclass.onRender.call(this, ct, position); this.wrap = this.el.wrap({cls:'x-form-field-wrap x-form-file-wrap'}); this.el.addClass('x-form-file-text'); this.el.dom.removeAttribute('name'); this.createFileInput(); var btnCfg = Ext.applyIf(this.buttonCfg || {}, { text: this.buttonText }); this.button = new Ext.Button(Ext.apply(btnCfg, { renderTo: this.wrap, cls: 'x-form-file-btn' + (btnCfg.iconCls ? ' x-btn-icon' : '') })); if(this.buttonOnly){ this.el.hide(); this.wrap.setWidth(this.button.getEl().getWidth()); } this.addFileListener(); }, createFileInput : function() { this.fileInput = this.wrap.createChild({ id: this.getFileInputId(), name: this.name||this.getId(), cls: 'x-form-file', tag: 'input', type: 'file', size: 1 }); }, addFileListener : function() { this.fileInput.on({ change: function(){ var v = this.fileInput.dom.value; this.setValue(v); this.fireEvent('fileselected', this, v); }, mouseover: function() { this.button.addClass(['x-btn-over','x-btn-focus']) }, mouseout: 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']) }, scope : this }); }, reset : function(){ this.fileInput.removeAllListeners(); this.fileInput.remove(); this.createFileInput(); this.addFileListener(); Ext.form.FileUploadField.superclass.reset.call(this); } });
Потом, после загрузка файла не забудьте использовать метод reset();
Источник: http://www.sencha.com/forum/showthread.php?46716-2.2-FileUploadField-reset-proposed-solution
Последние комментарии