为什么我的ExtJS表单没有提交?

时间:2012-06-05 16:01:48

标签: javascript extjs submit

我使用ExtJS弹出一个带有简单编辑表单的窗口,但是在按下提交按钮时,没有进行XHR调用,我在控制台中报告了this.form.el.dom is undefined错误。

这是我的代码:

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();
});

任何关于这个主题的亮点都会受到高度赞赏和大肆投票。

1 个答案:

答案 0 :(得分:6)

我要说的是,这个问题是形式提交的异议性质。在从Ajax提交事件收到响应之前,您将关闭。尝试在成功处理块中移动editWindow.close()行。