Close extjs window after submitting form

I have an extjs2 formpanel:

var fsf = new Ext.FormPanel({ labelWidth: 75, // label settings here cascade unless overridden frame:true, id: 'formPanel', title: 'Simple Form with FieldSets', bodyStyle:'padding:5px 5px 0', width: 550, items: [{ xtype:'fieldset', checkboxToggle:true, title: 'User Information', autoHeight:true, defaults: {width: 210}, defaultType: 'textfield', collapsed: true, items :[{ fieldLabel: 'First Name', name: 'first', allowBlank:false },{ fieldLabel: 'Last Name', name: 'last' },{ fieldLabel: 'Company', name: 'company' }, { fieldLabel: 'Email', name: 'email', vtype:'email' } ] },{ xtype:'fieldset', title: 'Phone Number', collapsible: true, autoHeight:true, defaults: {width: 210}, defaultType: 'textfield', items :[{ fieldLabel: 'Home', name: 'home', value: '(888) 555-1212' },{ fieldLabel: 'Business', name: 'business' },{ fieldLabel: 'Mobile', name: 'mobile' },{ fieldLabel: 'Fax', name: 'fax' } ] }], buttons: [{ text: 'Save', handler: function(){ var form = Ext.getCmp('formPanel').getForm(); if(form.isValid()) form.submit({ waitMsg:'Loading...', url: 'RepeatSession.jsp', success: function(form,action) { //we have to close the window here!! }, failure: function(form,action){ Ext.MessageBox.alert('Erro',action.result.data.msg); } }); } },{ text: 'Cancel' }] }); 

and window:

  win = new Ext.Window( { layout: 'fit', width: 500, height: 300, modal: true, closeAction: 'hide', items: fsf }); win.show(); 

As you can see, the form panel is inside the window as an element. I have to close the window after the form is submitted successfully, but I don’t know how to access the window object inside my success handler.

How can I hide the window after the form is submitted successfully?

+6
source share
1 answer

Just save the link to the window or one of its children before creating the form. For example, you can use a button parameter that skips the handler :

  handler: function(button, e){ 

[...]

  success: function(form,action) { button.up('.window').close(); }, 

Or, since you probably already have a window in the variable ( win ), you can simply use this to close the window:

 win.close(); 

but it depends on the fact that the win variable is available inside the success function, which we cannot accept from the code you specified.

+7
source

Source: https://habr.com/ru/post/909405/


All Articles