-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathbootstrapdatepicker.js
193 lines (188 loc) · 5.66 KB
/
bootstrapdatepicker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
function init(Survey, $) {
const iconId = "icon-datepicker";
Survey.SvgRegistry && Survey.SvgRegistry.registerIconFromSvg(iconId, require('svg-inline-loader?classPrefix!./images/datepicker.svg'), "");
$ = $ || window.$;
if (
!!$ &&
!$.fn.bootstrapDP &&
!!$.fn.datepicker &&
!!$.fn.datepicker.noConflict
) {
$.fn.bootstrapDP = $.fn.datepicker.noConflict();
if (!$.fn.datepicker) {
$.fn.datepicker = $.fn.bootstrapDP;
}
}
var widget = {
name: "bootstrapdatepicker",
title: "Date picker",
iconName: iconId,
widgetIsLoaded: function () {
return !!$ && !!$.fn.bootstrapDP;
},
isFit: function (question) {
return question.getType() === "bootstrapdatepicker";
},
htmlTemplate:
"<input class='form-control widget-datepicker' type='text' style='width: 100%;'>",
activatedByChanged: function (activatedBy) {
Survey.JsonObject.metaData.addClass(
"bootstrapdatepicker",
[
{ name: "inputType", visible: false },
{ name: "inputFormat", visible: false },
{ name: "inputMask", visible: false },
],
null,
"text"
);
Survey.JsonObject.metaData.addProperties("bootstrapdatepicker", [
{
// Can take a string or an Object.
// https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#format
name: "dateFormat",
category: "general",
default: "mm/dd/yyyy",
},
{
// Can take a string
name: "language",
category: "general",
default: "en",
},
{
// Can take a Date or a string
// https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#options
name: "startDate",
category: "general",
default: "",
},
{
// Can take a Date or a string
// https://bootstrap-datepicker.readthedocs.io/en/latest/options.html#options
name: "endDate",
category: "general",
default: "",
},
{
name: "todayHighlight:boolean",
category: "general",
default: true,
},
{
name: "weekStart:number",
category: "general",
default: 0,
},
{
name: "startView:number",
category: "general",
default: 0,
},
{
name: "minViewMode:number",
category: "general",
default: 0,
},
{
name: "maxViewMode:number",
category: "general",
default: 4,
},
{
name: "clearBtn:boolean",
category: "general",
default: false,
},
{
name: "autoClose:boolean",
category: "general",
default: true,
},
{
name: "daysOfWeekDisabled:string",
category: "general",
default: "",
},
{
name: "daysOfWeekHighlighted:string",
category: "general",
default: "",
},
{
name: "disableTouchKeyboard:boolean",
category: "general",
default: true,
},
]);
},
afterRender: function (question, el) {
var $el = $(el).is(".widget-datepicker")
? $(el)
: $(el).find(".widget-datepicker");
const options = {
enableOnReadonly: false,
format: question.dateFormat,
language: question.language,
todayHighlight: question.todayHighlight,
weekStart: question.weekStart,
startView: question.startView,
minViewMode: question.minViewMode,
maxViewMode: question.maxViewMode,
clearBtn: question.clearBtn,
autoclose: question.autoClose,
daysOfWeekDisabled: question.daysOfWeekDisabled,
daysOfWeekHighlighted: question.daysOfWeekHighlighted,
disableTouchKeyboard: question.disableTouchKeyboard,
};
if (!!question.startDate || !!question.renderedMin) {
options.startDate = !!question.startDate
? question.startDate
: question.renderedMin;
}
var renderedMax = question.renderedMax;
if (!!renderedMax && new Date(renderedMax).getFullYear() >= 2999) {
renderedMax = undefined;
}
if (!!question.endDate || !!renderedMax) {
options.endDate = !!question.endDate ? question.endDate : renderedMax;
}
const pickerWidget = $el.bootstrapDP(options).on("change", function (e) {
var newDate = pickerWidget.bootstrapDP("getUTCDate");
var newValue = newDate && newDate.toUTCString();
if (question.value != newValue) {
question.value = newValue;
}
});
question.valueChangedCallback = function () {
pickerWidget.bootstrapDP(
"setUTCDate",
!!question.value ? new Date(question.value) : ""
);
};
question.valueChangedCallback();
question.readOnlyChangedCallback = function () {
if (question.isReadOnly) {
$el.prop("readonly", true);
} else {
$el.removeAttr("readonly");
}
};
question.readOnlyChangedCallback();
},
willUnmount: function (question, el) {
var $el = $(el).is(".widget-datepicker")
? $(el)
: $(el).find(".widget-datepicker");
$el.bootstrapDP("destroy");
question.readOnlyChangedCallback = undefined;
question.valueChangedCallback = undefined;
},
pdfQuestionType: "text",
};
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");
}
if (typeof Survey !== "undefined") {
init(Survey, window.$);
}
export default init;