PDA

View Full Version : Posting values in Listview on a form



paologallo
24 Jan 2011, 2:37 AM
Hallo, i'm a newbie in Extjs and just want to know what's the best solution for posting values contained on a listview (listview inside a form), during submit.

Thanks in advance to all.

mitchellsimoens
24 Jan 2011, 8:15 AM
What you will have to do is right before you submit the form, you will have to create an object based on the Store values.

So use store.each(function(record) {}) and add a key and value to the object based on the record.

Now when you do your submit, you can add the params.


form.getForm().submit({
params: paramObj,
....
});

drunkmoose
5 Apr 2011, 7:11 AM
Hi Mitchell,

Thanks for the heads up regarding this. Once again, your posts prove very useful.

I tried your suggestion:



var paramObj = [];

selectedListsStore.each(
function (r) {
paramObj.push({id:r.data["id"], display_name:r.data["display_name"]});
}
);

Ext.getCmp("completeForm").getForm().submit({
params: paramObj,
success: function (r, a) {
alert("Yay!");
}
});


According do Firebug, this generates a POST request like this:



[object Object] 0
[object Object] 1
mailboxCombo
rb-phone PHONENEW
rb-voicemail NO
rg-company CHS
selectedMailinglist
smartphones Please make a choice...


And a POST string like:



%5Bobject%20Object%5D=0&%5Bobject%20Object%5D=1&rg-company=CHS&selectedMailinglist=&mailboxCombo=&rb-voicemail=NO&rb-phone=PHONENEW&smartphones=Please%20make%20a%20choice...


Obviously, that doesn't look like what we are looking for. Is it my object's structure that's bad ?

Thanks. :)

mitchellsimoens
5 Apr 2011, 7:22 AM
Your param object should be something like this:


params: {
id : 1,
something: 1,
good: 1
}

The keys should just be strings

drunkmoose
5 Apr 2011, 7:37 AM
There is more than 1 record in the store.

So, this is what I did. The paramObj is an array of objects, so here it is:



paramObj = Ext.encode(paramObj);
Ext.getCmp("completeForm").getForm().submit({
params: {
listViewItems: paramObj

},
success: function (r, a) {
alert("Yay!");
}

});


This is now the POST request being generated:



listViewItems [{"id":"0","display_name":"All_Tous"},{"id":"117","display_name":"Techs (distribution)"},{"id":"177","display_name":"etfs"}]
mailboxCombo
rb-phone PHONENEW
rb-voicemail NO
rg-company CHS
selectedMailinglist
smartphones Please make a choice...


But I'm worried listViewItems will be a JSON object, which my server side won't handle :(

mitchellsimoens
5 Apr 2011, 7:43 AM
it will be JSON

drunkmoose
5 Apr 2011, 8:04 AM
So what I need is:



params: {
listViewItems[0]["id"] = 1,
listViewItems[0]["name"] = "Whatever",
listViewItems[1]["id"] = 2,
listViewItems[1]["name"] = "Yeah",

// so on....
}


But I'm at a loss as to how I will generate this programatically. params probably won't take a string I could build and passing an object results in JSON...

mitchellsimoens
5 Apr 2011, 8:07 AM
In an array, you don't need to specify the index


var myArray = [];

myArray[0] = "Hi";
myArray[1] = "Hello";
//this is the same as above
myArray[] = "Hi";
myArray[] = "Hello";

drunkmoose
5 Apr 2011, 8:14 AM
Riiiight, same as in PHP. Sorry, JS is not the first language I learnt...

mitchellsimoens
5 Apr 2011, 8:16 AM
No prob!

drunkmoose
5 Apr 2011, 10:39 AM
myArray[] = "Hey";

Doesn't work. "Unexpected token ]"

Looks like this is for PHP only.

mitchellsimoens
5 Apr 2011, 10:43 AM
You're right, I was getting mixed up. (:|

drunkmoose
5 Apr 2011, 11:28 AM
Anyways, I chickened out, here's what I did



selectedListsStore.each(function (r) {
Ext.getCmp("completeForm").add({xtype: "hidden", id:"selectedLists", value: r.data["display_name"]});
Ext.getCmp("completeForm").doLayout();
}
);


Submits nicely and on my crappy 1997 classic ASP backend, the values are received in a comma separated fashion.