2012-10-31 44 views
2

我爲我的GUI使用extJS4,因此也顯示文件上傳對話框。 最後,我只想要一個按鈕,當我點擊它時會顯示文件上傳對話框,當我選擇它時,它會自動上傳文件。extJS中的文件上傳隱藏文本字段

對於自動「提交」,我知道我必須爲文件上傳對話框的onChange事件編寫處理程序。因此這不是問題。但有沒有辦法禁用文本字段,而不必訴諸於CSS? (當我選擇一個文件上傳名稱被寫入文本字段....我想要消除文本字段或至少使其不可見)。

回答

6

您搜索的屬性是buttonOnly: true

Here您發現本文件

只需將它添加到的例子是這樣的:

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

    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.'); 
        } 
       }); 
      } 
     } 
    }] 
});