Skip to content

Commit

Permalink
Do not reset question submissions (#270)
Browse files Browse the repository at this point in the history
* when questions are tried again, the existing answer will remain

* fix news bug number

* isolate on input$answer when displaying question_ui_initialize

* update comment
  • Loading branch information
schloerke committed Aug 7, 2019
1 parent 17e78f9 commit d06e6a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 8 additions & 2 deletions R/quiz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
)
}

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit d06e6a9

Please sign in to comment.