MDL-65217 core_form: use uniqie element ids in listing.
authorRuslan Kabalin <ruslan.kabalin@gmail.com>
Sun, 7 Apr 2019 20:13:21 +0000 (21:13 +0100)
committerMarina Glancy <marina@moodle.com>
Mon, 29 Apr 2019 12:23:26 +0000 (14:23 +0200)
lib/form/listing.php

index cd9477c..dc520b7 100644 (file)
@@ -110,19 +110,21 @@ class MoodleQuickForm_listing extends HTML_QuickForm_input {
     function toHtml() {
         global $CFG, $PAGE;
 
+        $this->_generateId();
+        $elementid = $this->getAttribute('id');
         $mainhtml = html_writer::tag('div', $this->items[$this->getValue()]->mainhtml,
-                array('id' => $this->getName().'_items_main', 'class' => 'formlistingmain'));
+                array('id' => $elementid . '_items_main', 'class' => 'formlistingmain'));
 
         // Add the main div containing the selected item (+ the caption: "More items").
         $html = html_writer::tag('div', $mainhtml .
                     html_writer::tag('div', $this->showall,
-                        array('id' => $this->getName().'_items_caption', 'class' => 'formlistingmore')),
-                    array('id'=>$this->getName().'_items', 'class' => 'formlisting hide'));
+                        array('id' => $elementid . '_items_caption', 'class' => 'formlistingmore')),
+                    array('id' => $elementid . '_items', 'class' => 'formlisting hide'));
 
         // Add collapsible region: all the items.
         $itemrows = '';
         $html .= html_writer::tag('div', $itemrows,
-                array('id' => $this->getName().'_items_all', 'class' => 'formlistingall'));
+                array('id' => $elementid . '_items_all', 'class' => 'formlistingall'));
 
         // Add radio buttons for non javascript support.
         $radiobuttons = '';
@@ -139,19 +141,19 @@ class MoodleQuickForm_listing extends HTML_QuickForm_input {
 
         // Container for the hidden hidden input which will contain the selected item.
         $html .= html_writer::tag('div', $radiobuttons,
-                array('id' => 'formlistinginputcontainer_' . $this->getName(), 'class' => 'formlistinginputcontainer'));
+                array('id' => 'formlistinginputcontainer_' . $elementid, 'class' => 'formlistinginputcontainer'));
 
         $module = array('name'=>'form_listing', 'fullpath'=>'/lib/form/yui/listing/listing.js',
             'requires'=>array('node', 'event', 'transition', 'escape'));
 
         $PAGE->requires->js_init_call('M.form_listing.init',
                  array(array(
-                'elementid' => $this->getName().'_items',
+                'elementid' => $elementid.'_items',
                 'hideall' => $this->hideall,
                 'showall' => $this->showall,
                 'hiddeninputid' => $this->getAttribute('id'),
                 'items' => $this->items,
-                'inputname' => $this->getName(),
+                'inputname' => $elementid,
                 'currentvalue' => $this->getValue())), true, $module);
 
         return $html;