From 8b5d12b9582daec55307faeac598b6676cd669cd Mon Sep 17 00:00:00 2001 From: Carl Ganz Date: Thu, 15 Jun 2017 20:00:39 -0700 Subject: [PATCH] Add placeholder parameter to updateTextInput (#1742) * add placeholder parameter * add js placeholder code * roxygenize * grunt * fix updateCheckBoxInput not to use placeholder * simply roxygen * add NEWS * revert grunt --- NEWS.md | 2 ++ R/update-input.R | 12 ++++++++---- man/updateTextAreaInput.Rd | 5 ++++- man/updateTextInput.Rd | 5 ++++- srcjs/input_binding_text.js | 6 +++++- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 74370d5a9..804fb5e3c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,8 @@ shiny 1.0.3.9000 * For `conditionalPanel`s, Shiny now gives more informative messages if there are errors evaluating or parsing the JavaScript conditional expression. ([#1727](https://github.com/rstudio/shiny/pull/1727)) +* Addressed [#1738](https://github.com/rstudio/shiny/issues/1738): The `updateTextInput` and `updateTextAreaInput` functions can now update the placeholder. ([#1742](https://github.com/rstudio/shiny/pull/1742)) + ### Bug fixes * Fixed [#1546](https://github.com/rstudio/shiny/issues/1546): make it possible (without any hacks) to write arbitrary data into a module's `session$userData` (which is exactly the same environment as the parent's `session$userData`). To be clear, it allows something like `session$userData$x <- TRUE`, but not something like `session$userData <- TRUE` (that is not allowed in any context, whether you're in the main app, or in a module) ([#1732](https://github.com/rstudio/shiny/pull/1732)). diff --git a/R/update-input.R b/R/update-input.R index e434aca11..9ec8b362f 100644 --- a/R/update-input.R +++ b/R/update-input.R @@ -2,6 +2,7 @@ #' #' @template update-input #' @param value The value to set for the input object. +#' @param placeholder The placeholder to set for the input object. #' #' @seealso \code{\link{textInput}} #' @@ -34,15 +35,15 @@ #' shinyApp(ui, server) #' } #' @export -updateTextInput <- function(session, inputId, label = NULL, value = NULL) { - message <- dropNulls(list(label=label, value=value)) +updateTextInput <- function(session, inputId, label = NULL, value = NULL, placeholder = NULL) { + message <- dropNulls(list(label=label, value=value, placeholder=placeholder)) session$sendInputMessage(inputId, message) } #' Change the value of a textarea input on the client #' #' @template update-input -#' @param value The value to set for the input object. +#' @inheritParams updateTextInput #' #' @seealso \code{\link{textAreaInput}} #' @@ -106,7 +107,10 @@ updateTextAreaInput <- updateTextInput #' shinyApp(ui, server) #' } #' @export -updateCheckboxInput <- updateTextInput +updateCheckboxInput <- function(session, inputId, label = NULL, value = NULL) { + message <- dropNulls(list(label=label, value=value)) + session$sendInputMessage(inputId, message) +} #' Change the label or icon of an action button on the client diff --git a/man/updateTextAreaInput.Rd b/man/updateTextAreaInput.Rd index b9235f8f0..063bb3ff9 100644 --- a/man/updateTextAreaInput.Rd +++ b/man/updateTextAreaInput.Rd @@ -4,7 +4,8 @@ \alias{updateTextAreaInput} \title{Change the value of a textarea input on the client} \usage{ -updateTextAreaInput(session, inputId, label = NULL, value = NULL) +updateTextAreaInput(session, inputId, label = NULL, value = NULL, + placeholder = NULL) } \arguments{ \item{session}{The \code{session} object passed to function given to @@ -15,6 +16,8 @@ updateTextAreaInput(session, inputId, label = NULL, value = NULL) \item{label}{The label to set for the input object.} \item{value}{The value to set for the input object.} + +\item{placeholder}{The placeholder to set for the input object.} } \description{ Change the value of a textarea input on the client diff --git a/man/updateTextInput.Rd b/man/updateTextInput.Rd index d5bfc29ee..0b6dde5b5 100644 --- a/man/updateTextInput.Rd +++ b/man/updateTextInput.Rd @@ -4,7 +4,8 @@ \alias{updateTextInput} \title{Change the value of a text input on the client} \usage{ -updateTextInput(session, inputId, label = NULL, value = NULL) +updateTextInput(session, inputId, label = NULL, value = NULL, + placeholder = NULL) } \arguments{ \item{session}{The \code{session} object passed to function given to @@ -15,6 +16,8 @@ updateTextInput(session, inputId, label = NULL, value = NULL) \item{label}{The label to set for the input object.} \item{value}{The value to set for the input object.} + +\item{placeholder}{The placeholder to set for the input object.} } \description{ Change the value of a text input on the client diff --git a/srcjs/input_binding_text.js b/srcjs/input_binding_text.js index 9abd9f05f..6e100a342 100644 --- a/srcjs/input_binding_text.js +++ b/srcjs/input_binding_text.js @@ -30,12 +30,16 @@ $.extend(textInputBinding, { if (data.hasOwnProperty('label')) $(el).parent().find('label[for="' + $escape(el.id) + '"]').text(data.label); + if (data.hasOwnProperty('placeholder')) + el.placeholder = data.placeholder; + $(el).trigger('change'); }, getState: function(el) { return { label: $(el).parent().find('label[for="' + $escape(el.id) + '"]').text(), - value: el.value + value: el.value, + placeholder: el.placeholder }; }, getRatePolicy: function() {