MDL-9136: Added a $selected attribute to the profile_field_menu object, which gets set during initialisation.

This commit is contained in:
nicolasconnault
2007-04-04 04:09:47 +00:00
parent 2d7617c67f
commit 7d4db46aa8
+7 -2
View File
@@ -2,6 +2,7 @@
class profile_field_menu extends profile_field_base {
var $options;
var $selected;
function profile_field_menu($fieldid) {
//first call parent constructor
@@ -10,8 +11,11 @@ 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();
foreach($options as $option) {
$this->options[] = format_string($option);//multilang formatting
foreach($options as $key => $option) {
$this->options[$key] = format_string($option);//multilang formatting
if ($option == $this->field->defaultdata) {
$this->selected = $key;
}
}
}
@@ -19,6 +23,7 @@ class profile_field_menu extends profile_field_base {
function display_field_add(&$mform) {
/// Create the form field
$mform->addElement('select', $this->inputname, format_string($this->field->name), $this->options);
$mform->setDefault($this->inputname, $this->selected);
}
/// Override base class method