PDA

View Full Version : Problem with addButton



gustavoh84
20 Aug 2009, 7:00 AM
Hi!
I can't add a button in the form. I can add fields, but not buttons. No error messages:



form = new Ext.FormPanel({
id: 'form_step_'+params['id'],
renderTo: 'panel_dynform'+params['id'],
labelWidth: 100,
url: '{% url workflow_work_add %}?id='+params['id'],
autoWidth: true,
title: 'Nova Operação',
frame: true,
defaults: { anchor: '100%' },
defaultType: 'textfield',
});
if (form_fields != '') {
form.add(form_fields);
form.addButton({
text: 'Salvar',
type: 'submit',
handler: function() {
Ext.getCmp(form).getForm().submit({
success: function(f,a){
Ext.Msg.alert('Success', 'It worked');
},
failure: function(f,a){
Ext.Msg.alert('Warning', 'Error');
}
})
}
});
//form.render();
form.doLayout();
}

carol.ext
20 Aug 2009, 7:56 AM
Read the FormPanel API (http://extjs.com/deploy/dev/docs/?class=Ext.form.FormPanel)description of addButton. It says:



addButton( String/Object config, Function handler, Object scope ) : Ext.Button
Adds a button to this panel. Note that this method must be called prior to rendering. The preferred approach is to add buttons via the buttons config.

You are rendering with renderTo in the config, so it happens before you add the button.

carol.ext
20 Aug 2009, 7:59 AM
FYI: Your code has a trailing comma that cause problems for you in Internet Explorer.


form = new Ext.FormPanel({
id: 'form_step_'+params['id'],
renderTo: 'panel_dynform'+params['id'],
labelWidth: 100,
url: '{% url workflow_work_add %}?id='+params['id'],
autoWidth: true,
title: 'Nova Operação',
frame: true,
defaults: { anchor: '100%' },
defaultType: 'textfield', <---- EXTRA/TRAILING comma
});

gustavoh84
20 Aug 2009, 8:32 AM
Hi! Thank you for anwser!
I'm using Firefox in Linux, so that problem does not affect my code.
My problem is the formpanel is appears but when call the method addButton, nothing button is inserted in the form.

carol.ext
20 Aug 2009, 11:50 AM
The comment about the comma was just informational. You read my first post?

gustavoh84
20 Aug 2009, 12:00 PM
Sorry, I didn't read your first post.
Now I understand.

Thank you!

FoxMulder900
1 Sep 2009, 1:34 PM
I too am having this problem, I understand that the addButton routine must be called before render, so is there another way to add a button dynamically?

FoxMulder900
1 Sep 2009, 1:42 PM
I figured it out - the buttons need to be added to the panels 'fbar' property.



form.fbar.addButton({text: 'Test Button'});
form.doLayout();

Jack9
1 Sep 2009, 2:00 PM
I typically add all the buttons and hide them by default. This is not optimal in many cases, so my interfaces are designed to statefully rebuild themselves every time a "potentially format changing" action is taken. I use in/visible trick very rarely.