Skip to content
Snippets Groups Projects
Commit 1c584f20 authored by Tim Hunt's avatar Tim Hunt
Browse files

Clearer validation messages in Interactive and DF modes.

These show up when the some of the inputs have been left blank, or need
to be verified, but there are no other more specific validation
messages.
parent ec1b319c
Branches
No related tags found
No related merge requests found
......@@ -237,6 +237,8 @@ $string['verifyquestionandupdate'] = 'Verify the question text and update the fo
// Strings used by input elements.
$string['booleangotunrecognisedvalue'] = 'Invalid input.';
$string['dropdowngotunrecognisedvalue'] = 'Invalid input.';
$string['pleaseananswerallparts'] = 'Please answer all parts of the question.';
$string['pleasecheckyourinputs'] = 'Please verify that what you entered was interpreted as expected.';
$string['singlechargotmorethanone'] = 'You can only enter a single character here.';
// Admin settings.
......
......@@ -407,6 +407,19 @@ class qtype_stack_question extends question_graded_automatically_with_countback
return $this->inputstates[$name];
}
/**
* @param array $response the current response being processed.
* @return boolean whether any of the inputs are blank.
*/
public function is_any_input_blank(array $response) {
foreach ($this->inputs as $name => $input) {
if (stack_input::BLANK == $this->get_input_state($name, $response)->status) {
return true;
}
}
return false;
}
public function is_any_part_invalid(array $response) {
// Invalid if any input is invalid, ...
foreach ($this->inputs as $name => $input) {
......@@ -447,8 +460,16 @@ class qtype_stack_question extends question_graded_automatically_with_countback
}
public function get_validation_error(array $response) {
// We don't use this method, but the interface requires us to have implemented it.
if ($this->is_any_part_invalid($response)) {
// There will already be a more specific validation error displayed.
return '';
} else if ($this->is_any_input_blank($response)) {
return get_string('pleaseananswerallparts', 'qtype_stack');
} else {
return get_string('pleasecheckyourinputs', 'qtype_stack');
}
}
public function grade_response(array $response) {
......
......@@ -73,9 +73,18 @@ class qtype_stack_renderer extends qtype_renderer {
$questiontext = str_replace("[[feedback:{$index}]]", $feedback, $questiontext);
}
return $this->question_tests_link($question, $options) .
$question->format_text($questiontext, $question->questiontextformat,
$result = '';
$result .= $this->question_tests_link($question, $options);
$result .= $question->format_text($questiontext, $question->questiontextformat,
$qa, 'question', 'questiontext', $question->id);
if ($qa->get_state() == question_state::$invalid) {
$result .= html_writer::nonempty_tag('div',
$question->get_validation_error($response),
array('class' => 'validationerror'));
}
return $result;
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment