Skip to content

Commit ec9c796

Browse files
committed
Questionnaire: improve navigation layout (#433)
* Responsive text input boxes. * Next' buttons right, 'Previous' button kept left. * Repeat notification/alert at the point of the error, so 'Please answer required question' would appear within the question. Co-authored-by: toanlam <[email protected]>
1 parent faeba26 commit ec9c796

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

questionnaire.class.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,22 +1249,22 @@ public function print_survey($quser, $userid=false) {
12491249
$this->survey_render($formdata, $formdata->sec, $msg);
12501250
$controlbuttons = [];
12511251
if ($formdata->sec > 1) {
1252-
$controlbuttons['prev'] = ['type' => 'submit', 'class' => 'btn btn-secondary',
1252+
$controlbuttons['prev'] = ['type' => 'submit', 'class' => 'btn btn-secondary control-button-prev',
12531253
'value' => '<< '.get_string('previouspage', 'questionnaire')];
12541254
}
12551255
if ($this->resume) {
1256-
$controlbuttons['resume'] = ['type' => 'submit', 'class' => 'btn btn-secondary',
1256+
$controlbuttons['resume'] = ['type' => 'submit', 'class' => 'btn btn-secondary control-button-save',
12571257
'value' => get_string('save_and_exit', 'questionnaire')];
12581258
}
12591259

12601260
// Add a 'hidden' variable for the mod's 'view.php', and use a language variable for the submit button.
12611261

12621262
if ($formdata->sec == $numsections) {
12631263
$controlbuttons['submittype'] = ['type' => 'hidden', 'value' => 'Submit Survey'];
1264-
$controlbuttons['submit'] = ['type' => 'submit', 'class' => 'btn btn-primary',
1264+
$controlbuttons['submit'] = ['type' => 'submit', 'class' => 'btn btn-primary control-button-submit',
12651265
'value' => get_string('submitsurvey', 'questionnaire')];
12661266
} else {
1267-
$controlbuttons['next'] = ['type' => 'submit', 'class' => 'btn btn-secondary',
1267+
$controlbuttons['next'] = ['type' => 'submit', 'class' => 'btn btn-secondary control-button-next',
12681268
'value' => get_string('nextpage', 'questionnaire').' >>'];
12691269
}
12701270
$this->page->add_to_page('controlbuttons', $this->renderer->complete_controlbuttons($controlbuttons));
@@ -1848,7 +1848,11 @@ private function response_check_format($section, $formdata, $checkmissing = true
18481848
}
18491849
if (!$this->questions[$questionid]->response_complete($formdata)) {
18501850
$missing++;
1851-
$strmissing .= get_string('num', 'questionnaire').$qnum.'. ';
1851+
$strnum = get_string('num', 'questionnaire').$qnum.'. ';
1852+
$strmissing .= $strnum;
1853+
// Pop-up notification at the point of the error.
1854+
$strnoti = get_string('missingquestion', 'questionnaire').$strnum;
1855+
$this->questions[$questionid]->add_notification($strnoti);
18521856
}
18531857
if (!$this->questions[$questionid]->response_valid($formdata)) {
18541858
$wrongformat++;

styles.css

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,37 @@ td.selected {
184184
float: right;
185185
}
186186

187+
#page-mod-questionnaire-complete .mod_questionnaire_controlbuttons {
188+
text-align: center;
189+
width: 100%;
190+
position: relative;
191+
}
192+
193+
#page-mod-questionnaire-complete .mod_questionnaire_controlbuttons .control-button-prev {
194+
float: left;
195+
}
196+
197+
#page-mod-questionnaire-complete .mod_questionnaire_controlbuttons .control-button-save {
198+
margin-left: 20%;
199+
}
200+
201+
#page-mod-questionnaire-complete .mod_questionnaire_controlbuttons .control-button-prev + .control-button-save {
202+
margin-left: 0;
203+
}
204+
205+
#page-mod-questionnaire-complete .mod_questionnaire_controlbuttons .control-button-next,
206+
#page-mod-questionnaire-complete .mod_questionnaire_controlbuttons .control-button-submit {
207+
float: right;
208+
}
209+
210+
#page-mod-questionnaire-complete .mod_questionnaire_controlbuttons input {
211+
margin-right: 0;
212+
}
213+
214+
#page-mod-questionnaire-complete .mod_questionnaire_completepage .generalbox .notice {
215+
padding: 0.5em 0 0.5em 0;
216+
}
217+
187218
/* progress bar styling */
188219

189220
#page-mod-questionnaire-complete .questionnaire-progressbar {
@@ -306,6 +337,17 @@ td.selected {
306337
margin-left: 0;
307338
}
308339

340+
.qn-answer > textarea,
341+
.qn-content .editor_atto_wrap .editor_atto_content {
342+
resize: vertical;
343+
}
344+
345+
.qn-answer textarea,
346+
.qn-answer input[type="text"] {
347+
box-sizing: border-box;
348+
height: auto;
349+
}
350+
309351
#notice .qn-question {
310352
margin: 0;
311353
}

templates/completepage.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@
7070
{{{formstart}}}
7171
{{#questions}}{{{.}}}{{/questions}}
7272
{{#pageinfo}}{{{.}}}{{/pageinfo}}
73-
<div class="notice" style="padding: 0.5em 0 0.5em 0.2em;">
74-
<div class="buttons">
73+
<div class="notice">
74+
<div class="buttons mod_questionnaire_controlbuttons">
7575
{{{controlbuttons}}}
7676
</div>
7777
</div>

tests/behat/checkbox_min_max_responses.feature

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ Feature: Checkbox questions can have forced minimum and maximum numbers of boxes
5555
Then I should see "Select one or two choices only"
5656
And I press "Submit questionnaire"
5757
Then I should see "Please answer required questions: #1. #2. #3."
58+
And I should see "Please answer required question #1."
59+
And I should see "Please answer required question #2."
60+
And I should see "Please answer required question #3."
5861
And I set the field "One" to "checked"
5962
And I set the field "Two" to "checked"
6063
And I set the field "Three" to "checked"

0 commit comments

Comments
 (0)