PDA

View Full Version : Multiselect ComboBox's getValue() returns different types



OraMartindale
23 Jan 2014, 8:20 AM
A ComboBox with multiselect=true will return an Array if you select items from the dropdown, but will return a string if you type values into the field.

I've created an example at https://fiddle.sencha.com/fiddle/2tc. You can test by selecting multiple items from the dropdown and then clicking the button. You will get an alert that says "Object". If you then type in the box (I added ", Bob" to the end of the already selected items) and click the button, you get an alert that says "string".

This feels like a but to me. I think the ComboBox's getValue() should return an Array no matter how it was selected.

If this is not a bug, but rather the intended result, what is the best practice for handling this?

scottmartin
28 Jan 2014, 12:58 PM
This is basic javascript .. it will convert to string when you add a string.

If you want to allow the user to manually input into the combo, then you can use split, or only allow existing selections in combo:
forceSelection: true



// from console:
cat = ["A", "B"];
dog = ', BOB';
mouse = cat + dog; // resulting string "A,B,BOB"

// use split to create array
mouse.split(','); // ["A", "B", "BOB"] array