MDL-30815 Choice Labels are now explicitly tied with input elements
authorAnkit Agarwal <ankit@moodle.com>
Thu, 9 Feb 2012 08:35:03 +0000 (14:05 +0530)
committerAnkit Agarwal <ankit@moodle.com>
Mon, 13 Feb 2012 02:56:45 +0000 (08:26 +0530)
mod/choice/renderer.php

index 4ef840d..1c4da2b 100644 (file)
@@ -46,10 +46,13 @@ class mod_choice_renderer extends plugin_renderer_base {
         $html .= html_writer::start_tag('ul', array('class'=>'choices' ));
 
         $availableoption = count($options['options']);
+        $choicecount = 0;
         foreach ($options['options'] as $option) {
+            $choicecount++;
             $html .= html_writer::start_tag('li', array('class'=>'option'));
             $option->attributes->name = 'answer';
             $option->attributes->type = 'radio';
+            $option->attributes->id = 'choice_'.$choicecount;
 
             $labeltext = $option->text;
             if (!empty($option->attributes->disabled)) {
@@ -58,7 +61,7 @@ class mod_choice_renderer extends plugin_renderer_base {
             }
 
             $html .= html_writer::empty_tag('input', (array)$option->attributes);
-            $html .= html_writer::tag('label', $labeltext, array('for'=>$option->attributes->name));
+            $html .= html_writer::tag('label', $labeltext, array('for'=>$option->attributes->id));
             $html .= html_writer::end_tag('li');
         }
         $html .= html_writer::tag('li','', array('class'=>'clearfloat'));