MDL-16242 "'Required' does nothing for select fields in customisable user profiles" added an extra option 'Choose...' which is the default if no other default is specified. If the user leaves the select field set to 'Choose...' then the required rule fails and the form does not submit.

This commit is contained in:
jamiesensei
2008-08-28 06:46:43 +00:00
parent 791a2be380
commit f1a022424d
+8 -1
View File
@@ -16,6 +16,9 @@ class profile_field_menu extends profile_field_base {
/// Param 1 for menu type is the options
$options = explode("\n", $this->field->param1);
$this->options = array();
if ($this->field->required){
$this->options[''] = get_string('choose').'...';
}
foreach($options as $key => $option) {
$this->options[$key] = format_string($option);//multilang formatting
}
@@ -40,7 +43,11 @@ class profile_field_menu extends profile_field_base {
* Overwrites the base class method
*/
function edit_field_set_default(&$mform) {
$defaultkey = (int)array_search($this->field->defaultdata, $this->options);
if (FALSE !==array_search($this->field->defaultdata, $this->options)){
$defaultkey = (int)array_search($this->field->defaultdata, $this->options);
} else {
$defaultkey = '';
}
$mform->setDefault($this->inputname, $defaultkey);
}