General developer forum

Disable default selection on 'autocomplete' mform element?

 
Picture of Jens Eeckhout
Disable default selection on 'autocomplete' mform element?
 
I've been trying for a while now to crack this issue, but haven't been able to figure it out.

I have a very simple form that features a user selector, which is an 'autocomplete' mform element. It works perfectly, apart from the fact that upon page load, it always selects the first available option.

Is there a way to disable this functionality? I'd like the element to just be completely empty when the page loads.

Code snippet:

// Autocomplete options
$options = [
'multiple' => false,
'noselectionstring' => get_string('choose_user', 'local_report'),
'placeholder' => get_string('type_here', 'local_report')
];
$form->addElement('autocomplete', 'id', get_string('choose_user_help', 'local_report'), $search, $options);
$form->addRule('id', null, 'required');

$search is a simple [$id => 'John Doe', ...] array.

I've tried using $form->setDefault(), but that does not seem to work. Any advice would be welcome!
 
Average of ratings: -
Picture of Jens Eeckhout
Re: Disable default selection on 'autocomplete' mform element?
 

Still have not found a solution for this. Hasn't anyone run into the same issue? Really need to fix this, but I can't find how.

 
Average of ratings: -
Picture of Stan Montgomery
Re: Disable default selection on 'autocomplete' mform element?
 

Hi Jens.

Where you able to add a default value here?

Stan.

 
Average of ratings: -