在ExtJS中,经常会需要用到一个窗口中嵌入一个form表单,进行表单提交,如下:
NewsTypesWindow=function(config){
config=config||{};
var formPanel=new Ext.form.FormPanel({
labelWidth:80,
url:mvcUrl,
labelAlign:'right',
defaults:{
anchor: '-20'
},
items:[
{xtype:'textfield',fieldLabel:'分类名称',name:'type_name',id:'type_name'},
{xtype:'textarea',fieldLabel:'分类描述',name:'type_desc',id:'type_desc'}
]
});
var thiz=this;
Ext.apply(config,{
width:300,
height:180,
iconCls:'news_window',
items:[formPanel],
buttons:[
{xtype:'button',text:'提交',iconCls:'save',handler:function(){
formPanel.getForm().submit({params:{
MVC_BUS:'NewTypes',
MVC_ACTION:'add'
}});
thiz.close();
}},
{xtype:'button',text:'关闭',iconCls:'delete',handler:function(){
thiz.close();
}}
]
});
NewsTypesWindow.superclass.constructor.call(this,config);
};
Ext.extend(NewsTypesWindow,Ext.Window,{});
提交表单并且关闭窗口。这个时候,会报出this.form.el is undefined的错误。
因为form在提交表单的时候,ajax提交表单是基于iframe的,需要去取window里面form的值,而form的window已经被异步的销毁,form dom已经回收。
正常情况下需要回调调用,如下:
{xtype:'button',text:'提交',iconCls:'save',handler:function(){
formPanel.getForm().submit({params:{
MVC_BUS:'NewTypes',
MVC_ACTION:'add'
},success:function(form,action){
thiz.close();
},failure:function(form,action){
thiz.close();
}});
}},