2012-06-05 65 views
2

我正在使用ExtJS彈出一個簡單的編輯窗體的窗口,但按下提交按鈕,沒有XHR調用,我得到一個this.form.el.dom is undefined錯誤報告在控制檯。爲什麼我的ExtJS表單不提交?

這裏是我的代碼:

var myNameSpace = new function(){ 
    var editForm, editWindow; 

    this.init = function(){ 

     Ext.Ajax.request({ 
      url: '/server/action.php', 
      success: function(result){ 
       console.log('ajax is working ok'); // I get this 
      } 
     }); 

     editForm = new Ext.form.FormPanel({ 
      width:450, 
      autoHeight: true, 
      header : false, 
      items: [{ 
       name: 'color', 
       fieldLabel: 'Color', 
       xtype: 'textfield', 
       value: 'blue' 
      }], 
      buttons: [{ 
       text:"Submit", 
       scope: this, // tried without this, too 
       handler: function(){ 
        // editForm.getForm().getValues() returns normal values 
        editForm.getForm().submit({ 
         url: '/server/action.php', 
         success: function(form, action) { 
          console.log('Yes! Success!'); // I don't get this 
         }, 
         failure: function(form, action) { 
          console.log('failed.'); // I don't get this 
         } 
        }); 
        editWindow.close(); // works 
        console.log('the form is now closed'); // I get this 
       } 
      }] 
     }); 

     editWindow = new Ext.Window(
     { 
      title:'Enter your color', 
      autoWidth: true, 
      autoHeight: true, 
      layout: 'fit', 
      modal: true, 
      items: editForm, 
      closeAction: 'hide' 
     }); 
     editWindow.show(); 
    }; 

}; 

Ext.onReady(function() { 
    myNameSpace.init(); 
}); 

關於這個問題的任何燈光,將不勝感激和大汗upvoted。

回答

5

我想說的是,問題是表單提交的異步性質。在從Ajax提交事件收到響應之前,您會關閉表單。嘗試在成功處理塊內移動您的editWindow.close()行。

+0

就是這樣!非常好的見解。非常感謝。 –

+0

歡迎您:) – dbrin