From: jamiesensei <jamiesensei> Date: Thu, 28 Aug 2008 06:44:49 +0000 (+0000) Subject: MDL-16242 "'Required' does nothing for select fields in customisable user profiles... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=d004c4adcd7ef66ec0da3a5304d292f60655fd58;p=moodle.git 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. --- diff --git a/user/profile/field/menu/field.class.php b/user/profile/field/menu/field.class.php index c360b2ad95..fa60ab631d 100644 --- a/user/profile/field/menu/field.class.php +++ b/user/profile/field/menu/field.class.php @@ -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); }