Skip to content

Commit

Permalink
add asis parameter to reset(); fixes #146
Browse files Browse the repository at this point in the history
  • Loading branch information
daattali committed Jul 14, 2020
1 parent e0e1c82 commit 6ed6fe8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions R/reset.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#'
#' @param id The id of the input element to reset or the id of an HTML
#' tag to reset all input elements inside it.
#' @param asis If \code{TRUE}, use the ID as-is even when inside a module
#' (instead of adding the namespace prefix to the ID).
#' @seealso \code{\link[shinyjs]{useShinyjs}},
#' \code{\link[shinyjs]{runExample}}
#' @note \code{shinyjs} must be initialized with a call to \code{useShinyjs()}
Expand Down Expand Up @@ -51,13 +53,13 @@
#' )
#' }
#' @export
reset <- function(id) {
reset <- function(id, asis = FALSE) {
# get the Shiny session
session <- getSession()

# Make sure reset works with namespaces (shiny modules)
nsName <- ""
if (inherits(session, "session_proxy")) {
if (inherits(session, "session_proxy") && !asis) {
id <- session$ns(id)
nsName <- session$ns("")
}
Expand Down Expand Up @@ -97,7 +99,12 @@ reset <- function(id) {
id <- substring(id, nchar(nsName) + 1)
}

funcParams <- list(session, id)
if (inherits(session, "session_proxy") && asis) {
session_to_reset <- .subset2(session, "parent")
} else {
session_to_reset <- session
}
funcParams <- list(session_to_reset, id)

# checkbox values need to be manually converted to TRUE/FALSE
if (type == "Checkbox") {
Expand Down
5 changes: 4 additions & 1 deletion man/reset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6ed6fe8

Please sign in to comment.