Hello,
Further to this docs page and this discussion, I am trying to replace a whole bunch of 'yes/no' dropdown lists with checkboxes in a block. I am surprised to find so few examples of using checkboxes in current core Moodle blocks.
Also, I have not found a single example showing how to store/retrieve a checkbox value to/from a block's config.
The only way I have managed to it get to work so far is as follows (using definition_after_data). Here is the edit_form of my test block:
class block_my_peers_edit_form extends block_edit_form {
protected function specific_definition($mform) {
$mform->addElement('checkbox', 'config_mytest','','Check this box for the test');
}
function definition_after_data(){
$mform =& $this->_form;
if(!$mform->getElementValue('config_mytest')){
$this->block->config->mytest = 0;
}
}
}
This does work, but is it the correct/best way of doing things? Are there drawbacks or alternative better ways? Why are there still so many instances of 'yes/no' dropboxes in Moodle core instead of the more ergonomic radiobuttons or checkboxes?
Joseph