From 3ba69818214c43980a6a36b90a613159a28d8598 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Wed, 4 Dec 2019 18:36:59 +0000 Subject: [PATCH] fix submit on enter getting json page --- BUGS.md | 1 + aprendizations/static/js/topic.js | 28 +++++++++++++--------------- aprendizations/templates/login.html | 5 +++-- aprendizations/templates/maintopics-table.html | 2 +- aprendizations/templates/rankings.html | 2 +- aprendizations/templates/topic.html | 4 +++- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/BUGS.md b/BUGS.md index 2a44e32..5b52e79 100644 --- a/BUGS.md +++ b/BUGS.md @@ -31,6 +31,7 @@ # FIXED +- enter nas respostas mostra json - apos clicar no botao responder, inactivar o input (importante quando o tempo de correcção é grande) - double click submits twice. - checkbox devia ter correct no intervalo [0,1] tal como radio. em caso de desconto a correccção faz 2*x-1. isto permite a mesma semantica nos dois tipos de perguntas. diff --git a/aprendizations/static/js/topic.js b/aprendizations/static/js/topic.js index 637a022..f197323 100644 --- a/aprendizations/static/js/topic.js +++ b/aprendizations/static/js/topic.js @@ -25,7 +25,6 @@ function showTriesLeft(tries) { function getQuestion() { $("#comments").html("").hide(); $("#submit").addClass("disabled"); - $.ajax({ type: "GET", url: "/question", @@ -37,18 +36,17 @@ function getQuestion() { // updates question in the page according to the response given by the server function updateQuestion(response) { - var method = response["method"]; var params = response["params"]; $("#right, #wrong").hide(); - switch (method) { + switch (response["method"]) { case "new_question": new_question(params["type"], params["question"], params["tries"], params["progress"]); break; case "finished_topic": $('#submit, #comments, #solution').remove(); - $("#content").html(response["params"]["question"]).animateCSS('tada'); + $("#content").html(params["question"]).animateCSS('tada'); $('#topic_progress').css('width', '100%').attr('aria-valuenow', 100); setTimeout(function(){window.location.replace('/course/');}, 2000); break; @@ -57,6 +55,7 @@ function updateQuestion(response) { function new_question(type, question, tries, progress) { window.scrollTo(0, 0); + $("#submit").hide(); $("#question_div").animateCSS('bounceOutUp', function() { $("#question_div").html(question); @@ -64,6 +63,14 @@ function new_question(type, question, tries, progress) { $("#question_div").animateCSS('bounceInDown', function() { showTriesLeft(tries); $("#submit").removeClass("disabled").show(); + + // disable enter in some question types (prevent submission on enter) + $("input:text, input:radio, input:checkbox").keydown(function (e) { + if (e.keyCode == 13 || e.keyCode == 169) { + e.preventDefault(); + return false; + } + }); }); }); var btntext = (type == "information") ? "Continuar" : "Responder"; @@ -76,14 +83,6 @@ function new_question(type, question, tries, progress) { $("div.list-group input:radio").eq(index).prop("checked", true); }); } - - // disable enter in some question types (prevent submission on enter) - $("input:text, input:radio, input:checkbox").keydown(function (e) { - if (e.keyCode == 13 || e.keyCode == 169) { - e.preventDefault(); - return false; - } - }); } @@ -108,15 +107,14 @@ function postAnswer() { } function getFeedback(response) { - var method = response["method"]; var params = response["params"]; - if (params['type'] == "information") { + if (params["type"] == "information") { getQuestion(); return; } - switch (method) { + switch (response["method"]) { case "right": $('#wrong').hide(); $('#comments').html(params['comments']).show(); diff --git a/aprendizations/templates/login.html b/aprendizations/templates/login.html index 7b1f9aa..86a1518 100644 --- a/aprendizations/templates/login.html +++ b/aprendizations/templates/login.html @@ -1,11 +1,12 @@ - - + + {{appname}} + diff --git a/aprendizations/templates/maintopics-table.html b/aprendizations/templates/maintopics-table.html index e42d55f..d75d73e 100644 --- a/aprendizations/templates/maintopics-table.html +++ b/aprendizations/templates/maintopics-table.html @@ -1,7 +1,7 @@ {% autoescape %} - + {{appname}} diff --git a/aprendizations/templates/rankings.html b/aprendizations/templates/rankings.html index 02cb8cd..919b99e 100644 --- a/aprendizations/templates/rankings.html +++ b/aprendizations/templates/rankings.html @@ -1,7 +1,7 @@ {% autoescape %} - + {{appname}} diff --git a/aprendizations/templates/topic.html b/aprendizations/templates/topic.html index a54b23b..4576b33 100644 --- a/aprendizations/templates/topic.html +++ b/aprendizations/templates/topic.html @@ -1,12 +1,14 @@ - + {{appname}} + +