diff --git a/NEWS.md b/NEWS.md index f2299f556..723fdf474 100644 --- a/NEWS.md +++ b/NEWS.md @@ -21,6 +21,8 @@ learnr 0.10.0 (unreleased) * Missing package dependencies will ask to be installed at tutorial run time. (@isteves, [#253](https://github.com/rstudio/learnr/issues/253)) +* When questions are tried again, the existing answer will remain, not forcing the user to restart from scratch. ([#270](https://github.com/rstudio/learnr/issues/270)) + ## Bug fixes diff --git a/R/quiz.R b/R/quiz.R index 9de2d311c..2e9c6782d 100644 --- a/R/quiz.R +++ b/R/quiz.R @@ -495,7 +495,10 @@ question_module_server_impl <- function( if (is.null(submitted_answer())) { # has not submitted, show regular answers return( - question_ui_initialize(question, submitted_answer()) + # if there is an existing input$answer, display it. + # if there is no answer... init with NULL + # Do not re-render the UI for every input$answer change + question_ui_initialize(question, isolate(input$answer)) ) } @@ -526,7 +529,10 @@ question_module_server_impl <- function( observeEvent(input$action_button, { if (button_type() == "try_again") { - init_question(NULL) + # maintain current submission / do not randomize answer order + # only reset the submitted answers + # does NOT reset input$answer + submitted_answer(NULL) # submit "reset" to server reset_question_submission_event(