I have an select autocomplete, that has multiple true. I would like to clear all selected items with javascript. This is the code I’m using:
const $sel = $('#' + selectId);
if (!$sel.length) {return;}
$sel.find('option:selected').prop('selected', false);
$sel[0].dispatchEvent(new Event('change', { bubbles: true }));
But is not working. This code is only working for multiple = false.
This is code of form element:
// View selections to show on booking options overview.
$options = array(
'multiple' => true
);
$mform->addElement(
'autocomplete',
'showviews',
get_string('showviews', 'booking'),
$whichviewopts,
$options
);
$mform->setType('showviews', PARAM_TAGLIST);
$defaults = array_keys($whichviewopts);
$mform->setDefault('showviews', $defaults);
Is there a way to programmatically clear selected items from java script and the programmatically select? It’s working only for single item. If I use multiple => true is not working.

