From 2aacd415e1794d04d67dbffc3c35547b7255b6be Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Fri, 5 Feb 2016 13:40:37 +0800 Subject: [PATCH] MDL-50484 mod_lesson: Use group to add multiple radio inputs https://docs.moodle.org/dev/lib/formslib.php_Form_Definition#radio Radio input should be added in group and not individual, so that each element created has unique id and template --- lib/formslib.php | 3 ++- mod/lesson/pagetypes/truefalse.php | 10 +++++++--- mod/lesson/styles.css | 22 +++++++++++++--------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/lib/formslib.php b/lib/formslib.php index a616133d5d0..e0639a24315 100644 --- a/lib/formslib.php +++ b/lib/formslib.php @@ -2651,7 +2651,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ 'actionbuttons'=>"\n\t\t".'
{element}
', - 'fieldset'=>"\n\t\t".'
{help}
{error}
{element}
', + 'fieldset'=>"\n\t\t".'
{help}
{error}
{element}
', 'static'=>"\n\t\t".'
{label}{req}{advancedimg} {help}
{error}
{element}
', @@ -2766,6 +2766,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{ $html =str_replace('{id}', 'fgroup_' . $group->getAttribute('id'), $html); $html =str_replace('{name}', $group->getName(), $html); $html =str_replace('{type}', 'fgroup', $html); + $html =str_replace('{class}', $group->getAttribute('class'), $html); $emptylabel = ''; if ($group->getLabel() == '') { $emptylabel = 'femptylabel'; diff --git a/mod/lesson/pagetypes/truefalse.php b/mod/lesson/pagetypes/truefalse.php index 5a8623d8c50..8ce8f094f60 100644 --- a/mod/lesson/pagetypes/truefalse.php +++ b/mod/lesson/pagetypes/truefalse.php @@ -409,24 +409,28 @@ class lesson_display_answer_form_truefalse extends moodleform { $mform->setType('pageid', PARAM_INT); $i = 0; + $radiobuttons = array(); foreach ($answers as $answer) { - $mform->addElement('html', '
'); $ansid = 'answerid'; if ($hasattempt) { $ansid = 'answer_id'; } - $mform->addElement('radio', $ansid, null, format_text($answer->answer, $answer->answerformat, $options), $answer->id, $disabled); + $radiobuttons[] = $mform->createElement('radio', $ansid, null, + format_text($answer->answer, $answer->answerformat, $options), $answer->id, $disabled); + $mform->setType($ansid, PARAM_INT); if ($hasattempt && $answer->id == $USER->modattempts[$lessonid]->answerid) { $mform->setDefault($ansid, $attempt->answerid); $mform->addElement('hidden', 'answerid', $answer->id); $mform->setType('answerid', PARAM_INT); } - $mform->addElement('html', '
'); $i++; } + $radiogroup = $mform->addGroup($radiobuttons, $ansid, '', array(''), false); + $radiogroup->setAttributes(array('class' => 'answeroptiongroup')); + if ($hasattempt) { $this->add_action_buttons(null, get_string("nextpage", "lesson")); } else { diff --git a/mod/lesson/styles.css b/mod/lesson/styles.css index c972a91c98c..382ce90c501 100644 --- a/mod/lesson/styles.css +++ b/mod/lesson/styles.css @@ -26,14 +26,18 @@ .path-mod-lesson .resourcecontent {text-align: center;} -.path-mod-lesson .answeroption .fcheckbox > span, -.path-mod-lesson .answeroption .fradio > span { +.path-mod-lesson .answeroption .fcheckbox > span { position: relative; float: left; } +.path-mod-lesson .answeroptiongroup .fgroup > span { + position: relative; + width: 100%; +} + .path-mod-lesson .answeroption .fcheckbox input, -.path-mod-lesson .answeroption .fradio input { +.path-mod-lesson .answeroptiongroup input { position: absolute; top: 2px; margin-top: 0px; @@ -41,28 +45,28 @@ } .path-mod-lesson .answeroption .fcheckbox label, -.path-mod-lesson .answeroption .fradio label { +.path-mod-lesson .mform .fitem.answeroptiongroup fieldset.fgroup label { padding-left: 20px; float: left; } -.path-mod-lesson .answeroption .felement label p:last-child { +.path-mod-lesson .answeroption .felement label p:last-child, +.path-mod-lesson .answeroptiongroup .felement label p:last-child { margin-bottom: 0px; } -.path-mod-lesson.dir-rtl .answeroption .fcheckbox > span, -.path-mod-lesson.dir-rtl .answeroption .fradio > span { +.path-mod-lesson.dir-rtl .answeroption .fcheckbox > span { float: right; } .path-mod-lesson.dir-rtl .answeroption .fcheckbox input, -.path-mod-lesson.dir-rtl .answeroption .fradio input { +.path-mod-lesson.dir-rtl .answeroptiongroup .fgroup input { left: inherit; right: 0; } .path-mod-lesson.dir-rtl .answeroption .fcheckbox label, -.path-mod-lesson.dir-rtl .answeroption .fradio label { +.path-mod-lesson.dir-rtl .mform .fitem.answeroptiongroup fieldset.fgroup label { padding-left: 0; padding-right: 20px; float: right;