Skip to content

Commit 3201380

Browse files
committed
Set value after min in max when updating dates
1 parent 1f04b39 commit 3201380

File tree

5 files changed

+38
-38
lines changed

5 files changed

+38
-38
lines changed

R/update-input.R

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,21 +179,18 @@ updateActionButton <- function(session, inputId, label = NULL, icon = NULL) {
179179
#' if (interactive()) {
180180
#'
181181
#' ui <- fluidPage(
182-
#' sliderInput("controller", "Controller", 1, 30, 10),
182+
#' sliderInput("n", "Day of month", 1, 30, 10),
183183
#' dateInput("inDate", "Input date")
184184
#' )
185185
#'
186186
#' server <- function(input, output, session) {
187187
#' observe({
188-
#' # We'll use the input$controller variable multiple times, so save it as x
189-
#' # for convenience.
190-
#' x <- input$controller
191-
#'
188+
#' date <- as.Date(paste0("2013-04-", input$n))
192189
#' updateDateInput(session, "inDate",
193-
#' label = paste("Date label", x),
194-
#' value = paste("2013-04-", x, sep=""),
195-
#' min = paste("2013-04-", x-1, sep=""),
196-
#' max = paste("2013-04-", x+1, sep="")
190+
#' label = paste("Date label", input$n),
191+
#' value = date,
192+
#' min = date - 3,
193+
#' max = date + 3
197194
#' )
198195
#' })
199196
#' }
@@ -241,20 +238,20 @@ updateDateInput <- function(session, inputId, label = NULL, value = NULL,
241238
#' if (interactive()) {
242239
#'
243240
#' ui <- fluidPage(
244-
#' sliderInput("controller", "Controller", 1, 30, 10),
241+
#' sliderInput("n", "Day of month", 1, 30, 10),
245242
#' dateRangeInput("inDateRange", "Input date range")
246243
#' )
247244
#'
248245
#' server <- function(input, output, session) {
249246
#' observe({
250-
#' # We'll use the input$controller variable multiple times, so save it as x
251-
#' # for convenience.
252-
#' x <- input$controller
247+
#' date <- as.Date(paste0("2013-04-", input$n))
253248
#'
254249
#' updateDateRangeInput(session, "inDateRange",
255-
#' label = paste("Date range label", x),
256-
#' start = paste("2013-01-", x, sep=""),
257-
#' end = paste("2013-12-", x, sep="")
250+
#' label = paste("Date range label", input$n),
251+
#' start = date - 1,
252+
#' end = date + 1,
253+
#' min = date - 5,
254+
#' max = date + 5
258255
#' )
259256
#' })
260257
#' }

man/updateDateInput.Rd

Lines changed: 6 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/updateDateRangeInput.Rd

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

srcjs/input_binding_date.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,6 @@ $.extend(dateInputBinding, {
6060
receiveMessage: function(el, data) {
6161
var $input = $(el).find('input');
6262

63-
if (data.hasOwnProperty('value'))
64-
this.setValue(el, data.value);
65-
6663
if (data.hasOwnProperty('label'))
6764
$(el).find('label[for="' + $escape(el.id) + '"]').text(data.label);
6865

@@ -72,6 +69,12 @@ $.extend(dateInputBinding, {
7269
if (data.hasOwnProperty('max'))
7370
this._setMax($input[0], data.max);
7471

72+
// Must set value only after min and max have been set. If new value is
73+
// outside the bounds of the previous min/max, then the result will be a
74+
// blank input.
75+
if (data.hasOwnProperty('value'))
76+
this.setValue(el, data.value);
77+
7578
$(el).trigger('change');
7679
},
7780
subscribe: function(el, callback) {

srcjs/input_binding_daterange.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,6 @@ $.extend(dateRangeInputBinding, dateInputBinding, {
8080
var $startinput = $inputs.eq(0);
8181
var $endinput = $inputs.eq(1);
8282

83-
if (data.hasOwnProperty('value'))
84-
this.setValue(el, data.value);
85-
8683
if (data.hasOwnProperty('label'))
8784
$el.find('label[for="' + $escape(el.id) + '"]').text(data.label);
8885

@@ -96,6 +93,12 @@ $.extend(dateRangeInputBinding, dateInputBinding, {
9693
this._setMax($endinput[0], data.max);
9794
}
9895

96+
// Must set value only after min and max have been set. If new value is
97+
// outside the bounds of the previous min/max, then the result will be a
98+
// blank input.
99+
if (data.hasOwnProperty('value'))
100+
this.setValue(el, data.value);
101+
99102
$el.trigger('change');
100103
},
101104
initialize: function(el) {

0 commit comments

Comments
 (0)