If anyone could help me with this it would be greatly appreciated! I have created an autocomplete form element like so:
$selected_options = array( '544', '717')
$multiselect = $mform->addElement('course', 'courses_array', get_string('certificate_courseSection','mod_certification'), $courselist, $options);
$multiselect->setMultiple(true);
$multiselect->setValue($selected_options)I am attempting to auto populate the selected element in the form utilising an array of values comprised of selected course ids like so.
$selected_options = array( '544', '717')
However when I attempt to select multiple default values I cannot do it.
I have tried
$multiselect->setSelected($selected_options)instead and also
$mform->setDefault('courses_array', $selected_options)but it does not work.
The only way I can get it to work is if I remove
$multiselect->setMultiple(true)
so it only displays a single choice and use
$multiselect->setValue($selected_options)
- however this only displays the last element in the $selected_options array when I require it to display multiple elements.