Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

ListBoxField Error No array values allowed with multiple=false


Go to End


7 Posts   1330 Views

Avatar
Scott Farmer

Community Member, 49 Posts

24 September 2014 at 5:09pm

Hi,

Getting this error when trying to use Listbox field with multiple selections.
[User Error] Uncaught InvalidArgumentException: No array values allowed with multiple=false

Tried using setMultiple(True) which doesn't seem to work. Hacking ListboxField.php and changing protected $multiple = false; to protected $multiple = true; fixes the issues but isn't a great solution.

This is my code:
$thelistboxfield = new ListBoxField("VehicleOptionalExtras", "Optional Extras", $this->getVehicleOptionalExtras(),unserialize(Session::get('Session_VehicleOptionalExtras')));
$thelistboxfield->setSize(10);
$thelistboxfield->setMultiple(true);

What am I missing?

Thanks
Regards
Scott

Avatar
camfindlay

Forum Moderator, 267 Posts

2 October 2014 at 3:55pm

Hi there, is this for use in the CMS or the frontend for users?

Avatar
Scott Farmer

Community Member, 49 Posts

2 October 2014 at 4:46pm

For the frontend thanks.

Avatar
kinglozzer

Community Member, 187 Posts

2 October 2014 at 9:21pm

Hi Scott,

Try changing your code to the following (note the extra two arguments):

$thelistboxfield = new ListBoxField("VehicleOptionalExtras", "Optional Extras", $this->getVehicleOptionalExtras(), unserialize(Session::get('Session_VehicleOptionalExtras')), 10, true);

Loz

Avatar
Scott Farmer

Community Member, 49 Posts

3 October 2014 at 10:59am

Thanks for your reply. Tried that, but still the same error. Also that was how it use to work on silverstripe 2.7x.

On the VehicleOptionalExtras select form field, it does appear that it is setting multiple=true correctly. Seems the setMultiple function is not updating $multiple variable to true in ListboxForm.php

Thanks
Regards
Scott

Avatar
UncleCheese

Forum Moderator, 4102 Posts

3 October 2014 at 2:43pm

You're trying to set the value before you set multiple to true. Try:

ListboxField::create('Name','Title')
->setMultiple(true)
->setSource($someOptions)
->setValue($someValues);

Avatar
Scott Farmer

Community Member, 49 Posts

3 October 2014 at 4:46pm

That worked, thanks for pointing that out. :-)