Skip to content

Commit 2a9a7cc

Browse files
committed
Enable noconflict for Bootstrap Datepicker. Closes rstudio#1346
1 parent c62e6b5 commit 2a9a7cc

File tree

3 files changed

+18
-11
lines changed

3 files changed

+18
-11
lines changed

R/input-date.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,5 +109,12 @@ dateInput <- function(inputId, label, value = NULL, min = NULL, max = NULL,
109109
datePickerDependency <- htmlDependency(
110110
"bootstrap-datepicker", "1.6.4", c(href = "shared/datepicker"),
111111
script = "js/bootstrap-datepicker.min.js",
112-
stylesheet = "css/bootstrap-datepicker3.min.css"
112+
stylesheet = "css/bootstrap-datepicker3.min.css",
113+
# Need to enable noConflict mode. See #1346.
114+
head = "<script>
115+
(function() {
116+
var datepicker = $.fn.datepicker.noConflict();
117+
$.fn.bootstrapDP = datepicker;
118+
})();
119+
</script>"
113120
)

srcjs/input_binding_date.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $.extend(dateInputBinding, {
1616
setValue: function(el, value) {
1717
// R's NA, which is null here will remove current value
1818
if (value === null) {
19-
$(el).find('input').val('').datepicker('update');
19+
$(el).find('input').val('').bootstrapDP('update');
2020
return;
2121
}
2222

@@ -25,7 +25,7 @@ $.extend(dateInputBinding, {
2525
if (isNaN(date))
2626
return;
2727

28-
$(el).find('input').datepicker('update', date);
28+
$(el).find('input').bootstrapDP('update', date);
2929
},
3030
getState: function(el) {
3131
var $el = $(el);
@@ -127,24 +127,24 @@ $.extend(dateInputBinding, {
127127
// null will unset.
128128
_setMin: function(el, date) {
129129
if (date === null) {
130-
$(el).datepicker('setStartDate', null);
130+
$(el).bootstrapDP('setStartDate', null);
131131

132132
} else {
133133
date = this._newDate(date);
134134
if (!isNaN(date))
135-
$(el).datepicker('setStartDate', date);
135+
$(el).bootstrapDP('setStartDate', date);
136136
}
137137
},
138138
// Given an unambiguous date string or a Date object, set the max (end) date
139139
// null will unset.
140140
_setMax: function(el, date) {
141141
if (date === null) {
142-
$(el).datepicker('setEndDate', null);
142+
$(el).bootstrapDP('setEndDate', null);
143143

144144
} else {
145145
date = this._newDate(date);
146146
if (!isNaN(date))
147-
$(el).datepicker('setEndDate', date);
147+
$(el).bootstrapDP('setEndDate', date);
148148
}
149149
},
150150
// Given a date string of format yyyy-mm-dd, return a Date object with

srcjs/input_binding_daterange.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,18 @@ $.extend(dateRangeInputBinding, dateInputBinding, {
2626
// null will remove the current value
2727
if (value.start !== undefined) {
2828
if (value.start === null) {
29-
$inputs.eq(0).val('').datepicker('update');
29+
$inputs.eq(0).val('').bootstrapDP('update');
3030
} else {
3131
var start = this._newDate(value.start);
32-
$inputs.eq(0).datepicker('update', start);
32+
$inputs.eq(0).bootstrapDP('update', start);
3333
}
3434
}
3535
if (value.end !== undefined) {
3636
if (value.end === null) {
37-
$inputs.eq(1).val('').datepicker('update');
37+
$inputs.eq(1).val('').bootstrapDP('update');
3838
} else {
3939
var end = this._newDate(value.end);
40-
$inputs.eq(1).datepicker('update', end);
40+
$inputs.eq(1).bootstrapDP('update', end);
4141
}
4242
}
4343
},

0 commit comments

Comments
 (0)