PDA

View Full Version : form.load()



bkraut
8 Sep 2009, 6:51 AM
Hi,

I'm using form load in my app. My form gets populated except complex fields.

Is there any way to tell form.load to use some Ext.data.Record structure?

Like:


var ReportForm = Ext.data.Record.create([
{name: 'id', type: 'int', allowBlank: false},
{name: 'nameSymbol', type: 'string', allowBlank: false},
{name: 'description', type: 'string', allowBlank: true},
{name: 'moduleId', type: 'string', allowBlank: false, mapping: 'module.id'},
{name: 'moduleName', type: 'string', allowBlank: false, mapping: 'module.name'}
]);


When I get json from server I get something like:



{"data":{"categories":{},"description":"Test","id":2,"module":{"active":true,"description":"Human Resources in general. Personal maps, salaries, education, ...","extensions":{"personalmaps":{"active":true,"description":"Personal Maps","fullName":"hrm.personalmaps","id":5,"module":null,"name":"Personal Maps","nameSymbol":"personalmaps"},"traveltickets":{"active":true,"description":"Travel Tickets - for the country and abroad. Daily Allowence, Traveling Expences, Meals Costs, ... ","fullName":"hrm.traveltickets","id":4,"module":null,"name":"Travel Tickets","nameSymbol":"traveltickets"},"salary":{"active":true,"description":"Employee Salaries","fullName":"hrm.salary","id":6,"module":null,"name":"Salary","nameSymbol":"salary"}},"guid":"b5f04e68-5ad3-4be3-b77a-dec7d018e709","iconCls":"x-hrm","id":33,"name":"Human Resources","nameSpace":"hrm","nameSymbol":"hrm"},"nameSymbol":"Test"},"message":"","success":true}


The case is that the module is a serialized object, so I need somehow to map it to moduleId hidden field in combo at the form.

Jack9
8 Sep 2009, 10:00 AM
var ReportForm = Ext.data.JsonReader(
// {}
// ,[
// {name: 'id', type: 'int', allowBlank: false},
// {name: 'nameSymbol', type: 'string', allowBlank: false},
// {name: 'description', type: 'string', allowBlank: true},
// {name: 'moduleId', type: 'string', allowBlank: false, mapping: 'module.id'},
// {name: 'moduleName', type: 'string', allowBlank: false, mapping: 'module.name'}
// ]
);

var testField = new Ext.form.TextField({
fieldLabel: 'Enter TestParam'
});

var newButton = new Ext.Button({
id: 'submitButton'
,text: 'Submit'
,handler:function(){
myFormPanel.getForm().load({
url: '/test/test.php'
,method: 'POST'
//,reader: ReportForm
,params: "TestParam="+testField.getValue()
,success: function(form, action) {
console.debug("success");
console.debug("Property:"+action.result.success);
console.debug("Data Property:"+action.result.data.description);
console.debug("Deep Property:"+action.result.data.module.extensions.personalmaps.fullName);
}
,failure: function(form, action) {
console.debug("fail");
}
});
}
});

var myFormPanel = new Ext.form.FormPanel({
title: 'Test Form Panel'
,width: 500
,items: [
testField
,newButton
]
});

myFormPanel.render("testDiv");
});See the console.debug messages to figure out how to pull values.

The following is a more readable version of the JSON. i dont think it maps to the initial reader you had set up =/

{
"success":true,
"message":"",
"data":
{
"categories":
{
},
"description":"Test",
"id":2,
"module":
{
"active":true,
"description":"Human Resources in general. Personal maps, salaries, education, ...",
"extensions":
{
"personalmaps":
{
"active":true,
"description":"Personal Maps",
"fullName":"hrm.personalmaps",
"id":5,
"module":null,
"name":"Personal Maps",
"nameSymbol":"personalmaps"
},
"traveltickets":
{
"active":true,
"description":"Travel Tickets - for the country and abroad. Daily Allowence, Traveling Expences, Meals Costs, ... ",
"fullName":"hrm.traveltickets",
"id":4,
"module":null,
"name":"Travel Tickets",
"nameSymbol":"traveltickets"
},
"salary":
{
"active":true,
"description":"Employee Salaries",
"fullName":"hrm.salary",
"id":6,
"module":null,
"name":"Salary",
"nameSymbol":"salary"
}
},
"guid":"b5f04e68-5ad3-4be3-b77a-dec7d018e709",
"iconCls":"x-hrm",
"id":33,
"name":"Human Resources",
"nameSpace":"hrm",
"nameSymbol":"hrm"
},
"nameSymbol":"Test"
}
}

bkraut
8 Sep 2009, 1:14 PM
Thanks,

I get my form populated except for the module field (see screenshot).

I corrected the load method with a reade, but no effect.



if (this.record && this.record.id) {
this.form.load({
url: 'Controller/Reporter/reportform.LoadReportForm',
reader: new Ext.data.JsonReader({
fields: [{
name: 'id',
type: 'int',
allowBlank: false
}, {
name: 'nameSymbol',
type: 'string',
allowBlank: false
}, {
name: 'description',
type: 'string',
allowBlank: true
}, {
name: 'moduleId',
type: 'string',
allowBlank: false,
mapping: 'module.id'
}, {
name: 'moduleName',
type: 'string',
allowBlank: false,
mapping: 'module.name'
}]
}),
params: {
id: this.record.id
},
waitMsg:'Loading...',
success: function(form, action) {
console.debug(form);
console.debug(action);
console.debug("Data Property:"+action.result.data.module.id);
},
failure: function(action, responseData) {
Ext.MessageBox.alert ("Error", Ext.decode(responseData.response.responseText).message);
}
});

ipreti
25 Sep 2009, 4:53 AM
Hi Guys,
Anyone knows the answer for that?
Im currently having the same problem.
Thanks.

hendricd
25 Sep 2009, 5:07 AM
Hi Guys,
Anyone knows the answer for that?
Im currently having the same problem.
Thanks.

Answer for what?

myForm.getForm().loadRecord(someRecord) ?

ipreti
25 Sep 2009, 12:53 PM
Hi hendricd,
My doubt is regarding loading nested objects (complex objects) to a form, specificly to a combobox.
I don't know how to map it in the load function.
I've tried the code above but it seems not to work.
Thanks in advance.

bkraut
27 Sep 2009, 2:10 AM
So what are you suggesting is instead of using form.load() method I should use some Ajax call to retrive an object and then load a form with a loadRecord method. I'm not going to use the record from the grid, as I have to achieve that my forms can be loaded from anywhere not just from the grid.

What I thik is that form.load is lacking te option to use record definitions. Inside success part of the load I can use setValue for a specific field, and like this I can achiev complete form fill, but ... If intead of using setValue I can use loadRecord I'll set some fields twice isn't that right?

bbxx
15 Oct 2009, 9:00 PM
Bump... I'm having this issue as well.

swadhina
15 Oct 2009, 11:12 PM
I am not able to load a simple text field itself... i m really new ti this ext js so plz pardon my ignorance...
Ext.onReady(function(){

var panGen = new Ext.FormPanel({
reader: new Ext.data.XmlReader(
{
record: 'Forms'
},[
{name: 'Title', mapping: 'Project'}
]
),
items:[
new Ext.form.FieldSet({items: [{xtype: 'textfield',
name: 'Title',
fieldLabel: 'Well Name',
listeners: {
'afterrender': function(){
panGen.getForm().load({url:'Well ConfigurationMgmt.xml', waitMsg:'Loading',method:'get'});

}}
}]
})
]
});

var viewport = new Ext.Viewport({
renderTo: 'EditForm',
items: [panGen]
});


});

this is the code ...

and the xml looks like this

<Forms FileID="" FormStage="" FormStatus="" >
<Project Title="test" CodeName="" EntryDate="" Formation="" >
</Project>
</Forms>