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
This commit is contained in:
+2
-1
@@ -2651,7 +2651,7 @@ class MoodleQuickForm_Renderer extends HTML_QuickForm_Renderer_Tableless{
|
||||
|
||||
'actionbuttons'=>"\n\t\t".'<div id="{id}" class="fitem fitem_actionbuttons fitem_{type}"><div class="felement {type}">{element}</div></div>',
|
||||
|
||||
'fieldset'=>"\n\t\t".'<div id="{id}" class="fitem {advanced}<!-- BEGIN required --> required<!-- END required --> fitem_{type} {emptylabel}"><div class="fitemtitle"><div class="fgrouplabel"><label>{label}<!-- BEGIN required -->{req}<!-- END required -->{advancedimg} </label>{help}</div></div><fieldset class="felement {type}<!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error" tabindex="0">{error}</span><br /><!-- END error -->{element}</fieldset></div>',
|
||||
'fieldset'=>"\n\t\t".'<div id="{id}" class="fitem {advanced} {class}<!-- BEGIN required --> required<!-- END required --> fitem_{type} {emptylabel}"><div class="fitemtitle"><div class="fgrouplabel"><label>{label}<!-- BEGIN required -->{req}<!-- END required -->{advancedimg} </label>{help}</div></div><fieldset class="felement {type}<!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error" tabindex="0">{error}</span><br /><!-- END error -->{element}</fieldset></div>',
|
||||
|
||||
'static'=>"\n\t\t".'<div class="fitem {advanced} {emptylabel}"><div class="fitemtitle"><div class="fstaticlabel">{label}<!-- BEGIN required -->{req}<!-- END required -->{advancedimg} {help}</div></div><div class="felement fstatic <!-- BEGIN error --> error<!-- END error -->"><!-- BEGIN error --><span class="error" tabindex="0">{error}</span><br /><!-- END error -->{element}</div></div>',
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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', '<div class="answeroption">');
|
||||
$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', '</div>');
|
||||
$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 {
|
||||
|
||||
+13
-9
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user