PDA

View Full Version : ComboBox MultiSelect returned values



marcus78
17 Jan 2012, 11:57 PM
Hi,

I'm using a comboBox with option multiSelect:true, and it works quite well.
However, when the form is submitted, I can see with Firebug that (if I select two values in the combo list) the same field appears twice in the posted variables. On the Php side, only one is received.
How to have an array submitted in posted variables, instead of twice the same field ?

Thanks in advance... and a happy new year, BTW !

Frith
18 Jan 2012, 1:06 AM
This is a bit of a hack but works for me:

Javascript: oSm is the selection model for the multiselect combobox.


prams['otherscount'] = oSm.selections.length; // total number of selections

for(i=0;i<oSm.selections.length;i++)
{
prams['others'+i] = oSm.selections.items[i].id;
}


frmPrep.submit({
method: 'POST',
url: '/pr/php/savePreparedReview.php',
//scope: this,
//callback: this.onResponse,
success: this.onResponse,
failure: this.onResponse,
//standardSubmit: true,
params: prams,
waitMsg: this.waitMsg,
waitTitle: this.waitTitle //will only be applicable if no waitMsgTarget specified
},this);



PHP:



$otherscount = $_REQUEST['otherscount'];

for($i=0;$i< $otherscount;$i++)
{
$sql = sprintf("INSERT INTO reviewOthers(reviewId, otherId) VALUES(%s,%s)", $revid, $_REQUEST['others'.$i]);
$result = mssql_query($sql,$conn);
if(!$result)
{
//mssql_query("delete from reviews where revId = ".$revid, $conn);
db_disconnect($conn);
echo '{"success":"false", "msg":"'.addslashes(mssql_get_last_message()).'<BR>'.addslashes($sql).'"}';
exit();
}
}


Hope this is of use

GH1UA
15 Feb 2012, 5:30 AM
I have the same problem.

Ext.form.action.Submit buildForm not correctly handled arrays.

This is my fix:


Ext.define('PWA.form.action.Submit', {
override: 'Ext.form.action.Submit',


/**
* @private
* Build a form element containing fields corresponding to all the parameters to be
* submitted (everything returned by {@link #getParams}.
* NOTE: the form element is automatically added to the DOM, so any code that uses
* it must remove it from the DOM after finishing with it.
* @return HTMLFormElement
*/
buildForm: function() {
var fieldsSpec = [],
formSpec,
formEl,
basicForm = this.form,
params = this.getParams(),
uploadFields = [];


basicForm.getFields().each(function(field) {
if (field.isFileUpload()) {
uploadFields.push(field);
}
});


function addField(name, val) {
fieldsSpec.push({
tag: 'input',
type: 'hidden',
name: name,
value: Ext.String.htmlEncode(val)
});
}


// Add the form field values
Ext.iterate(params, function(key, val) {
if (Ext.isArray(val)) {
Ext.each(val, function(v) {
addField(key+'[]', v);
});
} else {
addField(key, val);
}
});


formSpec = {
tag: 'form',
action: this.getUrl(),
method: this.getMethod(),
target: this.target || '_self',
style: 'display:none',
cn: fieldsSpec
};


// Set the proper encoding for file uploads
if (uploadFields.length) {
formSpec.encoding = formSpec.enctype = 'multipart/form-data';
}


// Create the form
formEl = Ext.DomHelper.append(Ext.getBody(), formSpec);


// Special handling for file upload fields: since browser security measures prevent setting
// their values programatically, and prevent carrying their selected values over when cloning,
// we have to move the actual field instances out of their components and into the form.
Ext.Array.each(uploadFields, function(field) {
if (field.rendered) { // can only have a selected file value after being rendered
formEl.appendChild(field.extractFileInput());
}
});


return formEl;
}
});


Good luck

Dafram
23 Jul 2012, 12:41 AM
Hi,

I'm using a comboBox with option multiSelect:true, and it works quite well.
However, when the form is submitted, I can see with Firebug that (if I select two values in the combo list) the same field appears twice in the posted variables. On the Php side, only one is received.
How to have an array submitted in posted variables, instead of twice the same field ?

Thanks in advance... and a happy new year, BTW !
Name the comboBox like this:


name: 'myname[]'

and it will submit a php array.

hasimseo
23 Jul 2012, 1:09 AM
var selected=selectedCombo.getValue();
.
.
params: {
param1:selected.join()
}


That will help you .
Good luck...

friend
23 Jul 2012, 4:47 AM
I think this is more of a PHP coding issue than an ExtJs issue. You have to designate the incoming request parameter as an array type on the server-side.

Mind you, I'm a Java developer and not a PHP coder. Regardless, when I submit a test form which contains a multiselect combobox with multiple values selected, I don't do anything special on the client side; just a simple form.submit(). This properly posts multiple request parameters, each having the same name with different values.

37403

I process the request parameters on the server-side as an array and it works as expected:



@PermitAll
@RequestMapping("/liaisons")
public @ResponseBody Map<String,Object> liaisons(@RequestParam("liaisons") Integer[] ids)
{
Map<String,Object> results = new HashMap<String,Object>();
results.put("success", true);
results.put("msg", "Total liaison IDs submitted: " + ids.length);
return results;
}

mark.gerosa
15 Mar 2013, 9:21 AM
I know that this post is quite old, but I run into the same issue and I saw this unanswered, so here my solution.

Suppose you have a variable where you want to save the values from the multiselection combobox; you can simply do this with this code:


var myVar = Ext.getCmp('MY_COMPONENT_ID').getValue().join();

then send myVar to the php file: you will see that the values are not splitted during POST.

if you then want to set the combobox multiselection:



Ext.getCmp('PERS_TREATMENT').setValue(customer.get('SPECIAL_TREATMENT').split(','));


hope this help!

M