From 7ec7a03aa0e058cd9bc37a99cca8352012a2a4f3 Mon Sep 17 00:00:00 2001 From: Dean Attali Date: Sat, 20 Aug 2016 11:16:46 -0700 Subject: [PATCH] add reset support for passwordInput and textAreaInput (fixes #78) --- NEWS.md | 3 ++- R/reset.R | 14 ++++++++++---- inst/srcjs/shinyjs-default-funcs.js | 10 ++++++++++ man/reset.Rd | 9 +++++---- 4 files changed, 27 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index eab736a..8326bfb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,9 +1,10 @@ # shinyjs 0.7 -2016-08-15 +2016-08-20 - All the colourpicker/colourInput related functions are now deprecated because I've made a more appropriate package for them [`colourpicker`](https://github.com/daattali/colourpicker) - Use updated colourpicker JS library that fixes bugs with new jquery version +- Add reset support for `passwordInput` and `textAreaInput` (#78) # shinyjs 0.6.2 diff --git a/R/reset.R b/R/reset.R index 06b9873..1eb03c0 100644 --- a/R/reset.R +++ b/R/reset.R @@ -5,10 +5,11 @@ #' all inputs within an HTML tag by providing the id of an HTML tag.\cr\cr #' Reset can be performed on any traditional Shiny input widget, which #' includes: textInput, numericInput, sliderInput, selectInput, -#' selectizeInput, radioButtons, dateInput, dateRangeInput, -#' checkboxInput, checkboxGroupInput. Buttons are not supported, -#' meaning that you cannot use this function to reset the value of an -#' action button back to 0. You also cannot use this function on a fileInput. +#' selectizeInput, radioButtons, dateInput, dateRangeInput, checkboxInput, +#' checkboxGroupInput, colourInput, passwordInput, textAreaInput. Note that +#' \code{actionButton} is not supported, meaning that you cannot reset +#' the value of a button back to 0. You also cannot use this function on +#' a \code{fileInput}. #' #' @param id The id of the input element to reset or the id of an HTML #' tag to reset all input elements inside it. @@ -84,6 +85,11 @@ reset <- function(id) { type <- messages[[x]][['type']] value <- messages[[x]][['value']] + # password inputs don't have an updatePasswordInput, they use text + if (type == "Password") { + type <- "Text" + } + updateFunc <- sprintf("update%sInput", type) # Make sure reset works with namespecing (shiny modules) diff --git a/inst/srcjs/shinyjs-default-funcs.js b/inst/srcjs/shinyjs-default-funcs.js index f55f1da..a65829f 100644 --- a/inst/srcjs/shinyjs-default-funcs.js +++ b/inst/srcjs/shinyjs-default-funcs.js @@ -355,6 +355,16 @@ shinyjs = function() { inputType = "Checkbox"; inputValue = input.prop('checked'); } + // passwordInput + else if (input.children("input[type='password']").length > 0) { + input = input.children("input[type='password']"); + inputType = "Password"; + } + // textAreaInput + else if (input.children("textarea").length > 0) { + input = input.children("textarea"); + inputType = "TextArea"; + } // if none of the above, no supported Shiny input was found else { foundInput = false; diff --git a/man/reset.Rd b/man/reset.Rd index 6e701eb..d5f8d2a 100644 --- a/man/reset.Rd +++ b/man/reset.Rd @@ -16,10 +16,11 @@ one specific input at a time by providing the id of a shiny input, or reset all inputs within an HTML tag by providing the id of an HTML tag.\cr\cr Reset can be performed on any traditional Shiny input widget, which includes: textInput, numericInput, sliderInput, selectInput, -selectizeInput, radioButtons, dateInput, dateRangeInput, -checkboxInput, checkboxGroupInput. Buttons are not supported, -meaning that you cannot use this function to reset the value of an -action button back to 0. You also cannot use this function on a fileInput. +selectizeInput, radioButtons, dateInput, dateRangeInput, checkboxInput, +checkboxGroupInput, colourInput, passwordInput, textAreaInput. Note that +\code{actionButton} is not supported, meaning that you cannot reset +the value of a button back to 0. You also cannot use this function on +a \code{fileInput}. } \note{ \code{shinyjs} must be initialized with a call to \code{useShinyjs()}