Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add placeholder parameter to numericInput and updateNumericInput #2341

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions R/input-numeric.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 6,9 @@
#' @param min Minimum allowed value
#' @param max Maximum allowed value
#' @param step Interval to use when stepping between min and max
#' @param placeholder A character string giving the user a hint as to what can
#' be entered into the control. Internet Explorer 8 and 9 do not support this
#' option.
#' @return A numeric input control that can be added to a UI definition.
#'
#' @family input elements
Expand All @@ -26,13 29,13 @@
#' }
#' @export
numericInput <- function(inputId, label, value, min = NA, max = NA, step = NA,
width = NULL) {
width = NULL, placeholder = NULL) {

value <- restoreInput(id = inputId, default = value)

# build input tag
inputTag <- tags$input(id = inputId, type = "number", class="form-control",
value = formatNoSci(value))
value = formatNoSci(value), placeholder = placeholder)
if (!is.na(min))
inputTag$attribs$min = min
if (!is.na(max))
Expand Down
6 changes: 4 additions & 2 deletions R/update-input.R
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 342,7 @@ updateNavlistPanel <- updateTabsetPanel
#' @param min Minimum value.
#' @param max Maximum value.
#' @param step Step size.
#' @param placeholder The placeholder to set for the input object.
#'
#' @seealso \code{\link{numericInput}}
#'
Expand Down Expand Up @@ -374,11 375,12 @@ updateNavlistPanel <- updateTabsetPanel
#' }
#' @export
updateNumericInput <- function(session, inputId, label = NULL, value = NULL,
min = NULL, max = NULL, step = NULL) {
min = NULL, max = NULL, step = NULL, placeholder = NULL) {

message <- dropNulls(list(
label = label, value = formatNoSci(value),
min = formatNoSci(min), max = formatNoSci(max), step = formatNoSci(step)
min = formatNoSci(min), max = formatNoSci(max), step = formatNoSci(step),
placeholder = placeholder
))
session$sendInputMessage(inputId, message)
}
Expand Down
6 changes: 5 additions & 1 deletion man/numericInput.Rd

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

4 changes: 3 additions & 1 deletion man/updateNumericInput.Rd

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

20 changes: 11 additions & 9 deletions srcjs/input_binding_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 19,24 @@ $.extend(numberInputBinding, textInputBinding, {
return "shiny.number";
},
receiveMessage: function(el, data) {
if (data.hasOwnProperty('value')) el.value = data.value;
if (data.hasOwnProperty('min')) el.min = data.min;
if (data.hasOwnProperty('max')) el.max = data.max;
if (data.hasOwnProperty('step')) el.step = data.step;
if (data.hasOwnProperty('value')) el.value = data.value;
if (data.hasOwnProperty('min')) el.min = data.min;
if (data.hasOwnProperty('max')) el.max = data.max;
if (data.hasOwnProperty('step')) el.step = data.step;
if (data.hasOwnProperty('placeholder')) el.placeholder = data.placeholder;

if (data.hasOwnProperty('label'))
$(el).parent().find('label[for="' $escape(el.id) '"]').text(data.label);

$(el).trigger('change');
},
getState: function(el) {
return { label: $(el).parent().find('label[for="' $escape(el.id) '"]').text(),
value: this.getValue(el),
min: Number(el.min),
max: Number(el.max),
step: Number(el.step) };
return { label: $(el).parent().find('label[for="' $escape(el.id) '"]').text(),
value: this.getValue(el),
min: Number(el.min),
max: Number(el.max),
step: Number(el.step),
placeholder: el.placeholder };
}
});
inputBindings.register(numberInputBinding, 'shiny.numberInput');