Cannot display help for element within a group

Cannot display help for element within a group

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

Here is a sample extract from my form

1 $mychoices = array(0,1,2,3,4);
2 $mygroup = [];
3 $mygroup[] = $mform->createElement('select', 'myelement0', 'label myelement0', array(0,1,2,3,4));
4 $mygroup[] = $mform->createElement('advcheckbox', 'myelement1', 'label myelement1');
5 $mform->addGroup($mygroup, 'mygroup');
6 $mform->addHelpButton('mygroup', 'help');
7 $mform->addHelpButton('mygroup[myelement1]', 'help');
8 $mform->hideIf('mygroup[myelement1]', 'mygroup[myelement0]', 'neq', 0);

And the result:

It all works as expected, except for the $mform->addHelpButton('mygroup[myelement1]', 'help') which throws an error:

"Trying to add help buttons to non-existent form elements : mygroup[myelement1]"

What does not look logical is that the form element mygroup[myelement1] is indeed recognized in the hideIf instruction (line 8) but considered as "non-existent" in the addHelpButton (line 7).

Any ideas? Is this a bug in the forms API?

Average of ratings: -
In reply to Joseph Rézeau

Re: Cannot display help for element within a group

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 can only add help icons on the group, not individual settings within the group.

Qtype_stack has some very complex groups, but once we realised this rule, we were able to work with it, and write help text for the group as a whole. Since the settings are usually related, it actually worked quite well in the end.