Skip to content

Commit

Permalink
add reset support for passwordInput and textAreaInput (fixes #78)
Browse files Browse the repository at this point in the history
  • Loading branch information
daattali committed Aug 20, 2016
1 parent 231990c commit 7ec7a03
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 9 deletions.
3 changes: 2 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
14 changes: 10 additions & 4 deletions R/reset.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 10 additions & 0 deletions inst/srcjs/shinyjs-default-funcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions man/reset.Rd

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

0 comments on commit 7ec7a03

Please sign in to comment.