PDA

View Full Version : [SOLVED] Problem Loading Form JsonReader



paulovitin
4 Jun 2008, 11:29 AM
Do not load values in fields...
I can't find what might be problem. Help me...


var formEdit = new Ext.form.FormPanel({
width : 450,
region: 'center',
labelAlign : 'right',
id : camelize(title),
bodyStyle : 'padding-top: 10px',
defaults : { allowBlank : false },
items : [{
xtype : 'textfield',
fieldLabel : 'Nome',
name : 'name',
id : 'name',
anchor : '80%'
},
{
xtype : 'textfield',
fieldLabel : 'Email',
name : 'email',
id : 'email',
anchor : '80%'
}],
reader : new Ext.data.JsonReader({
root : 'formEdit'
},
[{name : 'name', mapping: 'name'}, {name : 'email', mapping: 'email'}]),
buttons: [{
text : 'Salvar'

},{
text : 'Fechar',
handler : function(){ windows.Content.close(); }
}]
});

windows.Content.add(formEdit);
windows.Content.setSize(450, 150);
windows.Content.show(this);
formEdit.getForm().load({url:'php/url.php', waitMsg:'Carregando informações...'});

This is the data sent back

{success:true,"formEdit":{"name":"PAULO VITOR","email":"[email protected]"}}

Thanks!!

rvent
4 Jun 2008, 11:39 AM
JSON is bad...

paulovitin
4 Jun 2008, 11:45 AM
JSON is bad...

how so?

rvent
4 Jun 2008, 11:51 AM
Error:
Problem at line 1 character 2: Expected a string and instead saw success.

{success:true,"formEdit":{"name":"PAULO VITOR","email":"[email protected]"}}

http://jslint.com/

paulovitin
4 Jun 2008, 11:57 AM
Error:
Problem at line 1 character 2: Expected a string and instead saw success.

{success:true,"formEdit":{"name":"PAULO VITOR","email":"[email protected]"}}

http://jslint.com/

Now JSON is GOOD, but no worked... Is now?

{ "success" : true, "formEdit" : {"name" : "PAULO VITOR", "email" : "[email protected]" } }

rvent
4 Jun 2008, 12:01 PM
Show the code that forms your JSON...

paulovitin
4 Jun 2008, 12:07 PM
Show the code that forms your JSON...

No exist code. I wrote this to test...

I Checked in http://jslint.com/. It is good now.

rvent
4 Jun 2008, 12:11 PM
ok, you dont need mapping if the names of the fields are the same...

also, how do you know that you are getting that JSON..? did you copy that from firebug...?

how is that JSON getting to the browser...? This is your line of code: formEdit.getForm().load({url:'php/url.php'

whats is the contents of php/url.php....?

paulovitin
4 Jun 2008, 12:16 PM
ok, you dont need mapping if the names of the fields are the same...

also, how do you know that you are getting that JSON..? did you copy that from firebug...?

how is that JSON getting to the browser...? This is your line of code: formEdit.getForm().load({url:'php/url.php'

whats is the contents of php/url.php....?

php/url.php

<?
echo "{'success':true, 'formEdit':{'name' : 'PAULO VITOR', 'email' : '[email protected]'}}";
?>

rvent
4 Jun 2008, 12:40 PM
the "JSON" you are echoing is bad...

paulovitin
4 Jun 2008, 12:44 PM
the "JSON" you are echoing is bad...

I'm sorry. Checked now..

rvent
4 Jun 2008, 12:51 PM
There is an example that ships with ExtJS make sure you check it..

go to the examples and find "Loading/Saving a Dynamic Form using XML" It is the same thing except that you are using JSON...

paulovitin
4 Jun 2008, 3:23 PM
There is an example that ships with ExtJS make sure you check it..

go to the examples and find "Loading/Saving a Dynamic Form using XML" It is the same thing except that you are using JSON...

I see this. Any idea of what more can be?

rvent
4 Jun 2008, 5:24 PM
Everything that you need to get it working is there...

Use this link to troubleshoot your loadexception for your datastore: http://extjs.com/forum/showthread.php?t=27784

and this to find usefull links. Since this is not the first time that this has come up.
http://www.google.com/coop/cse?cx=011693920879787039234%3Az7of1ufqccu

I use that google link a lot and i find most of my answers there. Give it a shot and if it cant be found come back.

I was on your shoes once(and still am), expecting a clear example of everything i needed, until mjlecomte made me see that asking about the code and not howtos is how you learn a lot more.

I spent many hours reading the example i gave you on my previous post and then many more looking on the google link i posted and doing that i got my stuff working.

Anyways i am at home and all my projects are at the office. Give it a shot on your own and i ll help you...

rvent
4 Jun 2008, 5:26 PM
why dont you try using the php function json_encode. just as a practice for when you get more involved in more complex data records.

rvent
5 Jun 2008, 5:57 AM
Oh, well.. I dont know how this is different from the examples, but here ya go..

My fields are set on form load so you would have to modify it so it loads on a click event.



var jobDataRecord = new Ext.data.Record.create([
{name: 'WOrder'},
{name: 'WODateIn', renderer: Ext.util.Format.dateRenderer('m/d/y')},
{name: 'WODateOut', renderer: Ext.util.Format.dateRenderer('m/d/y')},
{name: 'WOCreatedAt'},
{name: 'WOUpdatedAt'},
{name: 'WOCompletedAt'},
{name: 'WOPartQuantity'},
{name: 'WOrderID'},
{name: 'PartNumberID'},
{name: 'PartLocationID'},
{name: 'PartPriorityID'},
{name: 'PartStateID'},
{name: 'PartstatusID'}
]);

var jobDataReader = new Ext.data.JsonReader({
root: 'results'
},
jobDataRecord
);

var jobDataProxy = new Ext.data.HttpProxy({
url: '../../../index.php/listboards/getJobDetails',
method: 'POST'
});

var jobDataStore = new Ext.data.Store({
proxy: jobDataProxy,
reader: jobDataReader,
});

// Form items
var workOrder = new Ext.form.NumberField({
readOnly: true,
fieldLabel: 'Work Order',
name: 'WOrder',
width: 120
});

var quantity = new Ext.form.NumberField({
readOnly: true,
fieldLabel: 'Part QTY',
name: 'WOPartQuantity',
width: 80
});

var state = new Ext.form.TextField({
readOnly: true,
fieldLabel: 'Part State',
name: 'PartState',
width: 120
});

var status = new Ext.form.TextField({
readOnly: true,
fieldLabel: 'Part Status',
name: 'PartStatus',
width: 120
});

var location = new Ext.form.TextField({
readOnly: true,
fieldLabel: 'Part Location',
name: 'PartLocation',
width: 120
});

var priority = new Ext.form.TextField({
readOnly: true,
fieldLabel: 'Part Priority',
name: 'PartPriority',
width: 120
});

var parts = new Ext.form.TextField({
readOnly: true,
fieldLabel: 'Part #',
name: 'PartNumber',
width: 120
});

//Date Fields
var dateIn = new Ext.form.DateField({
readOnly: true,
hideTrigger: true,
fieldLabel: 'Date In',
name: 'WODateIn',
width: 80
});

var dateOut = new Ext.form.DateField({
readOnly: true,
hideTrigger: true,
fieldLabel: 'Date Out',
name: 'WODateOut',
width: 80
});

var dateUpdate = new Ext.form.TextField({
readOnly: true,
hideTrigger: true,
fieldLabel: 'Last Updated',
name: 'WOUpdatedAt',
width: 140
});

var dateCreate = new Ext.form.TextField({
readOnly: true,
hideTrigger: true,
fieldLabel: 'Created at',
name: 'WOCreatedAt',
width: 140
});
// end date

var panelCol1 = new Ext.Panel({
layout:'form',
columnWidth: .28,
items: [ workOrder, parts, priority]
});

var panelCol2 = new Ext.Panel({
layout:'form',
columnWidth: .25,
items: [ location, state, status, ]
});

var panelCol3 = new Ext.Panel({
layout:'form',
columnWidth: .20,
items: [ dateIn, dateOut, quantity ]
});

var panelCol4 = new Ext.Panel({
layout:'form',
columnWidth: .27,
items: [ dateCreate, dateUpdate ]
});

var fieldsPanel = new Ext.Panel({
layout:'column',
items: [ panelCol1, panelCol2, panelCol3, panelCol4 ]
});

var jobDetails= new Ext.FormPanel({
labelAlign: 'top',
bodyStyle:'padding:5px 5px 5px',
frame: true,
tools: [{ id: 'help'}],
hideBorders: true,
monitorValid:true,
waitMsgTarget: true,
width: 600,
items: [ fieldsPanel, msgPanel ]
});

var JobWindow = new Ext.Window({
id: 'JobWindow',
title: 'HST -- Job Details',
constrainHeader: true,
resizable: false,
modal: true,
autoHeight: true,
width: 600,
items: jobDetails
})

jobDetails.getForm().load({url: '../../../index.php/listboards/getJobDetails', params: {id: wo}});
JobWindow.show();


That produces something like on the picture attached..

paulovitin
5 Jun 2008, 11:23 AM
:(

rvent
5 Jun 2008, 12:18 PM
you already have enought information to get it working... So no crying and more working... :)

Did you see any loadexceptions...?

paulovitin
5 Jun 2008, 12:56 PM
No understand why, but used his method and it worked!

Thanks... =D>