MDL-65217 core_form: use uniqie element ids in listing.

This commit is contained in:
Ruslan Kabalin 2019-04-07 21:13:21 +01:00 committed by Marina Glancy
parent 54e067dd47
commit 0ceb6751aa

View 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;