How to make a list of options in Moodle 2.0

How to make a list of options in Moodle 2.0

by Martín Maglianesi -
Number of replies: 7
Hello.

First of all, excuse my English.

I'm reading Obsolete: Output API (Moodle 2.0) and do not understand why the document is marked as Obsolete. Specifically, I'm wanting to use the example of html_select that until a couple of months ago it worked. Now I get an error and not if there is another way to make a list of options.

Does anyone clarify how I can not make a list of options in Moodle 2.0?

Thank you very much.

Sincerely,

Martin Maglianesi
(Argentina)
Average of ratings: -
In reply to Martín Maglianesi

Re: How to make a list of options in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
You are asking why something in an Obsolete document does not work smile

The way to do it now is to use the html_writer::select method.
In reply to Tim Hunt

Re: How to make a list of options in Moodle 2.0

by Martín Maglianesi -
Thanks Tim for your replysmile

But where I can find documentation on html_writer?

I need to rewrite some modules and I have difficulty understanding aspects of screen outputs and the inclusion of the jQuery library (JavaScript). Have I not found or the documentation related to these issues has not yet been created?

Thank you very much.

Sincerely,

Martin
In reply to Martín Maglianesi

Re: How to make a list of options in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
html_writer has extensive PHP documenter docs, doesn't it? You can either read them directly from the source, or from http://phpdocs.moodle.org/.

The other way to learn how to use it, is to look at examples in the Moodle code where it is used.

The other docs you want are Development:Migrating_contrib_code_to_2.0, but they are a work in progress.
Average of ratings: Useful (1)
In reply to Tim Hunt

Re: How to make a list of options in Moodle 2.0

by Alejandro Michavila Pallarés -
Hi,

In my new module for 2.0 I want to display a list of options but neither of these two options work:

1.)
$menu = new moodle_select_menu; 
$menu->options = $gradebook_history_options; 
$menu->name = 'restore_gradebook_history'; 
$menu->selectedoption = $restore_gradebook_history; 
echo $OUTPUT->select_menu($menu);

From: http://docs.moodle.org/en/Development:What_to_do_about_weblib_methods_with_lots_of_arguments

2.)

$select = moodle_select::make($options, $name, $selected); // Required 
$select->nothinglabel = $nothing; 
$select->nothingvalue = $nothingvalue; 
$select->disabled = $disabled; 
$select->tabindex = $tabindex;
$select->id = $id; 
$select->listbox = $listbox; 
$select->multiple = $multiple; 
$select->add_classes($class); 
echo $OUTPUT->select($select);

From: http://docs.moodle.org/en/Development:Deprecated_functions_in_2.0

The first one displays this error:

Fatal error: Class 'moodle_select_menu' not found in /var/www/moodle/mod/newmodule/view.php on line 188

And the second one displays a white page.

Thanks.




In reply to Alejandro Michavila Pallarés

Re: How to make a list of options in Moodle 2.0

by Alejandro Michavila Pallarés -
Thanks to a particularly helpful Moodler called Iñaki Arenaza, I could do my list of options with this code fragment:

$options = array();
$options['value1'] = 'Text1';
$options['value2'] = 'Text2';
$options['value3'] = 'Text3';
$options['value4'] = 'Text4';
echo html_writer::select($options, 'mylistofoptions', 'value4');
In reply to Alejandro Michavila Pallarés

Re: How to make a list of options in Moodle 2.0

by Alejandro Michavila Pallarés -
Hi,

I have a list of options and a button (for my new module, 2.0 compatible), and I want to catch user's selection when button is pressed and reload the same page (view.php) with the user's selection as an URL parameter.

Can anybody tell me where can I find an example?.

This is my current code:

$options = array();
$options['value1'] = get_string('value1', 'newmodule');
$options['value2'] = get_string('value2', 'newmodule');

echo $OUTPUT->box_start('generalbox', 'notice');
echo $OUTPUT->container_start();
echo '<p align="center">';

echo html_writer::label(get_string('label', 'newmodule'), 'selectlabel');
echo html_writer::select($options, 'selectoptionslist', 'value1');
echo $OUTPUT->help_icon('selectoptionslist', 'newmodule');
echo '</p><br>';

//...Catch user's selection from list of options here and store in $param1...
//Otherwise:
$param1 = 1;

echo $OUTPUT->single_button(new moodle_url('view.php', array('id' => $course->id, 'param1' => $param1)), get_string('savechanges', 'newmodule'));

echo $OUTPUT->container_end();
echo $OUTPUT->box_end();

With this code I can see the select menu list of options, and the button, but when I press the button I can see this error:

Coding error detected, it must be fixed by a programmer: The theme has already been set up for this page ready for output. Therefore, you can no longer change the theme, or anything that might affect what the current theme is, for example, the course.

Thanks.





In reply to Alejandro Michavila Pallarés

Re: How to make a list of options in Moodle 2.0

by Alejandro Michavila Pallarés -
That error is due to a bad calling method from $OUTPUT. I was calling methods from $OUTPUT before setting page (with $PAGE) and header with ($OUTPUT).