0

As described in Set the select option as blank as default in HTML select element, I would like to render a moodle select dropdown in a way that the initially displayed option isn't a valid option, instead it's just a notice to the user to select one of the below options:

<select>
  <option disabled selected value> -- select an option -- </option>
  <option>Option 1</option>
  <option>Option 2</option>
</select>

How do I pass the attributes "disabled" and "selected" (as suggested in the answer) to the option in moodle form?

This is my code so far:

$mform->addElement('select', 'mySelection', get_string('mySelection', 'local_myplugin'), array(
            'default' => get_string('-- select an option --', 'local_myplugin'),
            'option 1' => get_string('option_1', 'local_myplugin'),
            'option 2' => get_string('option_2', 'local_myplugin')
        ), ['class' => 'myclass']);
Madamadam
  • 842
  • 2
  • 12
  • 24

0 Answers0