MDL-30168 formslib: untangle automatic id generation.
commit515ff4db62cb5d031cdccec3356a94520e21bdd8
authorTim Hunt <T.J.Hunt@open.ac.uk>
Mon, 19 Dec 2011 18:22:28 +0000 (19 18:22 +0000)
committerTim Hunt <T.J.Hunt@open.ac.uk>
Fri, 23 Dec 2011 11:16:23 +0000 (23 11:16 +0000)
treed674f1ac31468b29b1df34bd8191cbc11fe613fc
parentddb7ae2f3cec5406a1c200839da10fdd8311c67a
MDL-30168 formslib: untangle automatic id generation.

Previously, we had overridden the _generateId method in almost all
subclasses; and then we mostly, but not always; ignored the value that
was generated there, and instead generated new (nicer) values in
MoodleQuickForm_Renderer::renderElement. Of course, that is not really a
logical place to (re)generate ids.

I have fixed the code so that the _generateId method now uses the 'nice
id' algorithm from renderElement. This should make the whole code flow
more logical.

This make all our overriding of _generateId unnecessary.

We do need a special _generateId for radio buttons, because you often
have different radio buttons with the same name but different values.

This change should only change the ids on radio, checkbox and
advcheckbox elements. Previously, those were essentially random, so I
don't think anyone could have been relying on the particular values.

This commit also has new unit tests, first to test the basic _generateId
algorithm, and then to create and render an example form (including some
tricky things like repeat_elements) and chech the acutal ids in the
generated HTML.
13 files changed:
lib/form/advcheckbox.php
lib/form/checkbox.php
lib/form/radio.php
lib/form/select.php
lib/form/selectgroups.php
lib/form/selectwithlink.php
lib/form/text.php
lib/form/url.php
lib/formslib.php
lib/pear/HTML/QuickForm/checkbox.php
lib/pear/HTML/QuickForm/element.php
lib/pear/HTML/QuickForm/radio.php
lib/simpletest/testformslib.php