* @param {String} formid HTML id of form
* @param {Array} questions
*/
- ensureRadiosChosen: function(formid, questions) {
+ ensureRadiosChosen: function(formid) {
// Prepare modal for display in case of problems.
var modalPromise = Str.get_strings([
{key: 'error', component: 'moodle'},
var form = $('#' + formid);
form.submit(function(e) {
- var error = false;
- questions.forEach(function(question) {
- var checkedResponse = form.find('input:radio[name="' + question.name + '"]:checked');
- if (checkedResponse.val() == question.default) {
- error = true;
- }
- });
-
- if (error) {
+ // Look for unanswered questions..
+ if (form.find('input:radio[data-survey-default="true"]:checked').length !== 0) {
e.preventDefault();
// Display the modal error.
modalPromise.then(function(modal) {
* @param object $question
*/
function survey_print_multi($question) {
- global $USER, $DB, $qnum, $checklist, $DB, $OUTPUT; //TODO: this is sloppy globals abuse
+ global $USER, $DB, $qnum, $DB, $OUTPUT; //TODO: this is sloppy globals abuse
$stripreferthat = get_string("ipreferthat", "survey");
$strifoundthat = get_string("ifoundthat", "survey");
echo $q->text ."</th>\n";
$default = get_accesshide($strdefault);
- echo "<td class=\"whitecell\"><label for=\"q$P$q->id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"q$P" . $q->id . "_D\" value=\"0\" checked=\"checked\" />$default</label></td>";
+ echo "<td class=\"whitecell\"><label for=\"q$P$q->id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"q$P" . $q->id . "_D\" value=\"0\" checked=\"checked\" data-survey-default=\"true\" />$default</label></td>";
for ($i=1;$i<=$numoptions;$i++) {
$hiddentext = get_accesshide($options[$i-1]);
$id = "q$P" . $q->id . "_$i";
echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$P$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
}
- $checklist["q$P$q->id"] = 0;
-
} else {
echo "<th scope=\"row\" class=\"optioncell\">";
echo "<b class=\"qnumtopcell\">$qnum</b> ";
echo "<span class=\"option\">$q->text</span></th>\n";
$default = get_accesshide($strdefault);
- echo '<td class="whitecell"><label for="qP'.$q->id.'"><input type="radio" name="qP'.$q->id.'" id="qP'.$q->id.'" value="0" checked="checked" />'.$default.'</label></td>';
+ echo '<td class="whitecell"><label for="qP'.$q->id.'"><input type="radio" name="qP'.$q->id.'" id="qP'.$q->id.'" value="0" checked="checked" data-survey-default="true" />'.$default.'</label></td>';
for ($i=1;$i<=$numoptions;$i++) {
echo "<span class=\"option\">$q->text</span></th>\n";
$default = get_accesshide($strdefault);
- echo '<td class="whitecell"><label for="q'. $q->id .'"><input type="radio" name="q'.$q->id. '" id="q'. $q->id .'" value="0" checked="checked" />'.$default.'</label></td>';
+ echo '<td class="whitecell"><label for="q'. $q->id .'"><input type="radio" name="q'.$q->id. '" id="q'. $q->id .'" value="0" checked="checked" data-survey-default="true" />'.$default.'</label></td>';
for ($i=1;$i<=$numoptions;$i++) {
$hiddentext = get_accesshide($options[$i-1]);
$id = "q" . $q->id . "_$i";
echo "<td><label for=\"$id\"><input type=\"radio\" name=\"q$q->id\" id=\"$id\" value=\"$i\" />$hiddentext</label></td>";
}
-
- $checklist["qP$q->id"] = 0;
- $checklist["q$q->id"] = 0;
}
echo "</tr>\n";
}
$questions = survey_get_questions($survey);
global $qnum; // TODO: ugly globals hack for survey_print_*().
-global $checklist; // TODO: ugly globals hack for survey_print_*().
$qnum = 0;
-$checklist = array();
foreach ($questions as $question) {
if ($question->type >= 0) {
exit;
}
-$questions = array();
-foreach ($checklist as $question => $default) {
- $questions[] = array('name' => $question, 'default' => $default);
-}
-$PAGE->requires->js_call_amd('mod_survey/validation', 'ensureRadiosChosen', array('surveyform', $questions));
+$PAGE->requires->js_call_amd('mod_survey/validation', 'ensureRadiosChosen', array('surveyform'));
echo '<br />';
echo '<input type="submit" class="btn btn-primary" value="'.get_string("clicktocontinue", "survey").'" />';