How do you load a select with items preselected when the chosen module is installed/enabled?
I’m doing the following:
$my_list = array('item1' = 'item1', 'item2' = 'item2', 'item3' = 'item3'); $form['list_info']['my_list'] = array( '#title' => t('Select a list to manage:'), '#type' => 'select', '#options' => $my_list, '#default_value' => $my_list, );
But the select shows up empty. Clicking it reveals the items and I can select them, but I need the chosen select to show up with the items selected. How’s this possible?
Your select item is currently only accepting one selected option. This is why it won't allow an array as a default value (it expects a string or int).
adding following line should work
'#multiple' => true,
Answered by Suranga Panagamuwa Gamage on December 3, 2020
2 Asked on March 2, 2021 by deinqwertz
1 Asked on February 25, 2021 by plambre
1 Asked on February 21, 2021 by hkguile
1 Asked on February 21, 2021 by bkudrle
1 Asked on February 18, 2021 by chris-riddell
0 Asked on February 17, 2021 by maxo
2 Asked on February 15, 2021 by acanana
3 Asked on February 13, 2021 by saidbakr
1 Asked on February 12, 2021 by athakhan
1 Asked on February 11, 2021
1 Asked on February 8, 2021 by dupls
1 Asked on February 7, 2021 by leelandra
2 Asked on February 6, 2021 by quest
Get help from others!