How can ExtJS4 give a different url to the same formpanel

  • 2020-03-30 02:46:10
  • OfStack

Formpanel can be used as an example on the API:
 
var panel=Ext.create('Ext.form.Panel', { 
title: 'Simple Form', 
bodyPadding: 5, 
width: 350, 

//This URL will be submitted via an AJAX request
//url: 'save-form.php', 

//The form Fields Fields will be lined up vertically, taking up the entire width
layout: 'anchor', 
defaults: { 
anchor: '100%' 
}, 

// The fields 
defaultType: 'textfield', 
items: [{ 
fieldLabel: 'First Name', 
name: 'first', 
allowBlank: false 
},{ 
fieldLabel: 'Last Name', 
name: 'last', 
allowBlank: false 
}], 

//Reset and save buttons.
buttons: [{ 
text: ' reset ', 
handler: function() { 
this.up('form').getForm().reset(); 
} 
}, { 
text: ' save ', 
formBind: true, //only enabled once the form is valid 
disabled: true, 
handler: function() { 
var form = this.up('form').getForm(); 
if (form.isValid()) { 
form.submit({ 
success: function(form, action) { 
Ext.Msg.alert(' Save success ', action.result.msg); 
}, 
failure: function(form, action) { 
Ext.Msg.alert(' The operation failure ', action.result.msg); 
} 
}); 
} 
} 
}], 
renderTo: Ext.getBody() 
); 

Look at the API, formpanel actually has no url configuration, also did not get the API function. It should be the parameter of the parent class of formpanel.

Then I looked at ext.form.basic, and sure enough, there was a url configuration entry.

FormPanel in Ext does not save the form data, which is saved by BasicForm. When submitting the form, you need to get the BasicForm in the current FormPanel to submit.

Once you get the BasicForm object, you can submit the form

Since there are two components to use in the project, the only difference between the two components is that the url submitted is different, so I did not define the url when I defined the component

Then you can add different urls to different containers as well, as in the example above

Where needed
 
panel.getForm().url='../LogSelectServlet';//You can assign different urls in different places like this

This approach is a good one for component reuse.

Related articles: