2016-09-07 32 views
0

我從ExtJs 4.1轉移到ExtJs 4.2,因爲filefield組件的可怕的麻煩。主要的問題是ExtJs 4.1在每次提交表單後,文件字段被清除。根據這thread,在ExtJs 4.2他們解決了這個問題,但是,我仍然面臨着我的應用程序中的同樣的問題,儘管事實上我設置了clearOnSubmitfalse。我甚至想通了什麼樣的代碼導致整個問題:Filefield with clearOnSubmit false仍然被清除

Ext.define('Ext.form.field.FileButton', { 
    ... 
createFileInput : function(isTemporary) { 
    var me = this; 
    //ATTENTION! 
    //before me.el.createChild is called 
    //me.fileInputEl contains initial filefield: 
    //<input id="filefield-2144-button-fileInputEl" class=" x-form-file-input" type="file" size="1" name="file_name" role=""> 
    me.fileInputEl = me.el.createChild({ 
     name: me.inputName, 
     id: !isTemporary ? me.id + '-fileInputEl' : undefined, 
     cls: me.inputCls, 
     tag: 'input', 
     type: 'file', 
     size: 1 
    }); 
    //ATTENTION! 
    //now initial fielfield is gone, even though we have set clearOnSubmit to false 
    me.fileInputEl.on('change', me.fireChange, me); 
    } 
... 

這個庫方法被稱爲在某一時刻,當表單提交給服務器和destroyes初始元素:

<input id="filefield-2144-button-fileInputEl" class=" x-form-file-input" type="file" size="1" name="file_name" role=""> 

,並取代它與一個新的空的:

<input name="file_name" id="ext-gen4414" class="x-form-file-input" type="file" size="1"> 

那麼,那有什麼問題,我該如何解決這個庫錯誤。

回答

2

我已經在4.2.1上測試過它。它的工作很好。提交後,文件不會被清除。

Ext.application({ 
    name: 'Fiddle', 

    launch: function() { 
     Ext.create('Ext.form.Panel', { 
      title: 'Upload a Photo', 
      width: 400, 
      bodyPadding: 10, 
      frame: true, 
      renderTo: Ext.getBody(), 
      items: [{ 
       xtype: 'filefield', 
       name: 'photo', 
       fieldLabel: 'Photo', 
       labelWidth: 50, 
       msgTarget: 'side', 
       allowBlank: false, 
       anchor: '100%', 
       buttonText: 'Select Photo...', 
       clearOnSubmit: false 
      }], 

      buttons: [{ 
       text: 'Upload', 
       handler: function() { 
        var form = this.up('form').getForm(); 
        if (form.isValid()) { 
         form.submit({ 
          url: 'photo-upload.php', 
          waitMsg: 'Uploading your photo...', 
          success: function(fp, o) { 
           Ext.Msg.alert('Success', 'Your photo "' + o.result.file + '" has been uploaded.'); 
          } 
         }); 
        } 
       } 
      }] 
     }); 
    } 
}); 
+1

爲此的提琴手。 https://fiddle.sencha.com/#fiddle/1gd2 – UDID

相關問題