Skip to content

Commit

Permalink
MDL-65217 core_form: use uniqie element ids in listing.
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin authored and marinaglancy committed Apr 29, 2019
1 parent 54e067d commit 0ceb675
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions lib/form/listing.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,21 @@ public function MoodleQuickForm_listing($elementName=null, $elementLabel=null, $
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 = '';
Expand All @@ -139,19 +141,19 @@ function toHtml() {

// 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;
Expand Down

0 comments on commit 0ceb675

Please sign in to comment.