PDA

View Full Version : Got stuck with FormPanel - form.load() - beg your pardon!



yaphoto
29 Jan 2008, 8:38 AM
Hello Guys,

giving up, have been reading a lot of forum posts today and could not find a solution. Can someone please help me run below code sucesfully?

The form renders in <div> tag as expecting but with empty fields.

My JSON response on the server is:
[{"bankname":"Rabobank (NL)","address":"some address"}]

The .js scripts:

Ext.onReady(function(){

Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';

var bankDetailsForm = new Ext.FormPanel({
applyTo: 'bank',
labelWidth: 100,
url:'save-form.php',
frame:true,
title: 'Simple Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 210},
defaultType: 'textfield',

items: [{
fieldLabel: 'Bank Name',
name: 'bankname',
allowBlank:false
},{
fieldLabel: 'Bank Address',
name: 'address'
}
],

buttons: [{
text: 'Save'
},{
text: 'Cancel'
}]
});
bankDetailsForm.form.load({url:'sections/bank/getBankDetails.php?bankid=11'});
});

What I am doing wrong?

Thx/Regards!

yaphoto
29 Jan 2008, 9:32 AM
Also, if this can help, below is attached the screen from the Firebug which shows weird error message.
In IE6 there are no js errors but form fields are still with no values.
Can someone get me out from the Dark, please?

yaphoto
29 Jan 2008, 12:33 PM
UPDATE: the Firebug error seemed to be caused by FF cache - after clearing the cache and restarting the pc no more Firebug errors.

But main problem still unresolved. I can not load JSON data to the form fields.
I have read that form.load() must be done after formPanel is rendered, so I even commented 'applyTo' parameter and put load command at the bottom of the script - no progress, fields still empty.


bankDetailsForm.render('bank');
//bankDetailsForm.getForm().load({url:'sections/bank/getBankDetails.php?bankid=11'});
bankDetailsForm.form.load({url:'sections/bank/getBankDetails.php?bankid=11'});

This is very annoying, I am really pissed of on myself - can not make any step forward!
Pls help desperate extjs newbie!

Condor
29 Jan 2008, 1:42 PM
You can only load data in a form if the form has a reader that can process the server response.

yaphoto
29 Jan 2008, 2:07 PM
Condor, many thanks for your time!

Digging on forum all-day-long and many times I have read that when comparing BasicForm and FormPanel - this 2nd doesn't require to set up the Reader as long as json structure and form's fields match each other. (?)

Will try to go to the light now, thanks!

cerad
29 Jan 2008, 2:10 PM
Dig your way down to the Ext.Form.Action.Load documentation.

Your JSON data needs to look like:


{
success: true,
data: {
clientName: "Fred. Olsen Lines",
portOfLoading: "FXT",
portOfDischarge: "OSL"
}
}

yaphoto
29 Jan 2008, 2:37 PM
Cerad, you're awesome!

I've changed the json format as you mentioned and form has been loaded with the data!

Now heavy question: guys, please advise which way shall I code further? Condor says "use reader", Cerad "change json format and load without reader". What I ask is what is the best way if we are saying I will be coding form submit and putting all wistles and bells in the GUI etc. ?

Again, thanks for your great support!

tunaboo
29 Jan 2008, 3:25 PM
Well any way you do it, you want correct JSON format.. which is

{name:'value',name2:'value2'}

Can't have quotes around name...

lobo-tuerto
29 Jan 2008, 9:55 PM
Well, in fact you can and you should:
http://simonwillison.net/2006/Oct/11/json/ -> keep your JSON valid. ;)

TheNakedPirate
30 Jan 2008, 12:38 AM
I posted a bunch of code on making a CRUD form here http://extjs.com/forum/showthread.php?t=24550

It may help you