Moodle

hierselect class of quickform is not defined in moodle

Details

  • Type: Improvement Improvement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 1.9.5
  • Fix Version/s: None
  • Component/s: Forms Library
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE

Description

Hierselect is a class to dynamically create two or more HTML Select elements. The first select changes the content of the second select and so on. Hierselect is not defined in lib/formslib.php and in lib/form directory. This class is important to get data from users in signup.

  1. MDL-20589-Patch.txt
    31/Dec/09 11:44 AM
    3 kB
    Stephen Bourget
  2. MDL-20589-Patchv2.txt
    31/Dec/09 12:07 PM
    4 kB
    Stephen Bourget

Activity

Hide
Stephen Bourget added a comment -

Attached is a patch that implements the hierselect form element in moodle. It is built against Moodle 2.0 dev (Build: 20091231)

Usage is as follows:

// level 0 array
$letters = array();
$letters[0] = 'A';
$letters[1] = 'B';
$letters[2] = 'C';

// level 1 array
$words = array();
$words[0][0] = 'Aardvark';
$words[0][1] = 'Apple';
$words[0][2] = 'Armadillo';
$words[1][0] = 'Ball';
$words[1][1] = 'Banana';
$words[2][0] = 'Cat';
$words[2][1] = 'Chicken';
$words[2][2] = 'Can';
$words[2][3] = 'Cow';

// add hierselect element
$attribs = array('size' => '4');
$hier = &$mform->addElement('hierselect', 'list', get_string('categories', 'modulename'), $attribs);
$hier->setOptions(array($letters, $words));

Show
Stephen Bourget added a comment - Attached is a patch that implements the hierselect form element in moodle. It is built against Moodle 2.0 dev (Build: 20091231) Usage is as follows: // level 0 array $letters = array(); $letters[0] = 'A'; $letters[1] = 'B'; $letters[2] = 'C'; // level 1 array $words = array(); $words[0][0] = 'Aardvark'; $words[0][1] = 'Apple'; $words[0][2] = 'Armadillo'; $words[1][0] = 'Ball'; $words[1][1] = 'Banana'; $words[2][0] = 'Cat'; $words[2][1] = 'Chicken'; $words[2][2] = 'Can'; $words[2][3] = 'Cow'; // add hierselect element $attribs = array('size' => '4'); $hier = &$mform->addElement('hierselect', 'list', get_string('categories', 'modulename'), $attribs); $hier->setOptions(array($letters, $words));
Hide
Stephen Bourget added a comment -

Updated patch.
Please ignore the earlier one, I had forgotten to include the changes to formslib.php

Show
Stephen Bourget added a comment - Updated patch. Please ignore the earlier one, I had forgotten to include the changes to formslib.php
Hide
David Mudrak added a comment -

Question for Petr Skoda: is there any reason why we do not support Quickform's hierselect in formslib? I know there is a plan to replace QuickForms but this looks like a nice feature and we have patch already...

Show
David Mudrak added a comment - Question for Petr Skoda: is there any reason why we do not support Quickform's hierselect in formslib? I know there is a plan to replace QuickForms but this looks like a nice feature and we have patch already...
Hide
Petr Škoda (skodak) added a comment -

Accessibility:
Did anybody test how is looks, ehm "sounds" in the screen readers?
Does it work without javascript too?

Show
Petr Škoda (skodak) added a comment - Accessibility: Did anybody test how is looks, ehm "sounds" in the screen readers? Does it work without javascript too?
Hide
Barry Oosthuizen added a comment -

hierselect elements can't work without Javascript because the second/following select boxes have their options stored in a javascript array. Here is an example page: http://www.testbooking.com/booking.php

Show
Barry Oosthuizen added a comment - hierselect elements can't work without Javascript because the second/following select boxes have their options stored in a javascript array. Here is an example page: http://www.testbooking.com/booking.php
Hide
Stephen Bourget added a comment -

I did test it with firevox, a free screen reader for firefox, (http://firevox.clcworld.net/downloads.html) and it performed as well as the regular select lists in Moodle.

As for the javascript, It mostly works with javascript disabled.
This is how I tested it:

1. I turned off all javascript using the web developer toolbar
2. Loaded the form with the hierselect element

The hierselect element is rendered correctly and the first selection list is fully populated.
The second selection list will only display the items that correspond with the item that was selected in the first selection list

For example, if your arrays were:

// level 0 array
$letters = array();
$letters[0] = 'A';
$letters[1] = 'B';
$letters[2] = 'C';

// level 1 array
$words = array();
$words[0][0] = 'Aardvark';
$words[0][1] = 'Armadillo';
$words[1][0] = 'Ball';
$words[1][1] = 'Banana';
$words[2][0] = 'Cat';
$words[2][1] = 'Chicken';

When you first load the form, the entire $letters array is displayed, and only the items from $words[0][X] are displayed (Assuming the defaults were 0,0).
If you select 'B' from the first array and then save / reload the page then the items from $words[1][X] are displayed.

Show
Stephen Bourget added a comment - I did test it with firevox, a free screen reader for firefox, (http://firevox.clcworld.net/downloads.html) and it performed as well as the regular select lists in Moodle. As for the javascript, It mostly works with javascript disabled. This is how I tested it: 1. I turned off all javascript using the web developer toolbar 2. Loaded the form with the hierselect element The hierselect element is rendered correctly and the first selection list is fully populated. The second selection list will only display the items that correspond with the item that was selected in the first selection list For example, if your arrays were: // level 0 array $letters = array(); $letters[0] = 'A'; $letters[1] = 'B'; $letters[2] = 'C'; // level 1 array $words = array(); $words[0][0] = 'Aardvark'; $words[0][1] = 'Armadillo'; $words[1][0] = 'Ball'; $words[1][1] = 'Banana'; $words[2][0] = 'Cat'; $words[2][1] = 'Chicken'; When you first load the form, the entire $letters array is displayed, and only the items from $words[0][X] are displayed (Assuming the defaults were 0,0). If you select 'B' from the first array and then save / reload the page then the items from $words[1][X] are displayed.
Hide
Barry Oosthuizen added a comment -

Could you make the hierselect element work like the popupform() function? (when javascript is off a 'go' button appears)

Show
Barry Oosthuizen added a comment - Could you make the hierselect element work like the popupform() function? (when javascript is off a 'go' button appears)

People

Dates

  • Created:
    Updated: