how to implement dependent dropdown lists?

how to implement dependent dropdown lists?

by Joseph Rézeau -
Number of replies: 4
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

I am currently developing a block to export entries & definitions from a course glossary and import into the quiz question bank. I've got it to work but would like to add the feature or selecting glossary categories (if any).

On the page where the teacher can select which glossary to export data from plus various other parameters (number of entries, randomize, etc.) I would like to have 2 "dependent dropdown lists", Glossaries and Categories. When teacher selects a glossary in the Glossaries list, I would like the Categories list to dynamically be populated with the names of that glossary's categories (if any).

I have not found that kind of parameters settings page in moodle. If there are existing examples in moodle, please direct me to them. To have an idea of what I would like to achieve, see Chained Selects.

As an alternative, I could always display on my block's settings page the complete list of available glossaries (within the course context) and for each, the list of its categories, and provide all those items with radio buttons, but that would not be so sleek.

Any help welcome,

Joseph

PS.- This is for 1.9; maybe there is a better mechanism already existing in the 2.0 API?

Average of ratings: Useful (1)
In reply to Joseph Rézeau

Re: how to implement dependent dropdown lists?

by Joseph Rézeau -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Plugin developers Picture of Testers Picture of Translators

Never mind, I will use the choose_from_menu_nested() function which does nicely what I need.

Joseph

PS.- I'm still interested in developers' view of dependent dropdown lists.

In reply to Joseph Rézeau

Re: how to implement dependent dropdown lists?

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

There is nothing in formslib, not in 1.x or 2.0. It would be possible to make such an element, but it would be a fair amount of work.

In reply to Tim Hunt

Re: how to implement dependent dropdown lists?

by Patrick Pollet -

Hello,


I did it quite easily on Moodle 1.9 by adding the QuickForm Component 'hierselect' http://www.php-editors.com/pear_manual/package.html.html-quickform.html-quickform-hierselect.html in lib/form and adding the following line at the end of lib/formslib.php

 

MoodleQuickForm::registerElementType('hierselect', "$CFG->libdir/form/hierselect.php", 'MoodleQuickForm_hierselect');

So I could add hierarchical selects in some of my customized forms wink

Of course it requires one little patch at every upgrade ...

 

If you can read french ( Joseph do ...), see http://moodle.org/mod/forum/discuss.php?d=140392

Cheers.

 

Edit : There is a tracker entry on this : http://tracker.moodle.org/browse/MDL-20589 , but unfortunately the tracker is down at the moment ;-(

Average of ratings: Useful (2)