Skip to content

Commit 68df03c

Browse files
added bootstrapdatepicker
1 parent 0168b46 commit 68df03c

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

src/bootstrapdatepicker.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
function init(Survey) {
2+
// $ = $ || window.$;
3+
var widget = {
4+
name: "bootstrapdatepicker",
5+
title: "Date picker",
6+
iconName: "icon-datepicker",
7+
widgetIsLoaded: function () {
8+
return !!$.fn.datepicker;
9+
},
10+
isFit: function (question) {
11+
return question.getType() === "bootstrapdatepicker";
12+
},
13+
htmlTemplate:
14+
"<input class='form-control widget-datepicker' type='text' style='width: 100%;'>",
15+
activatedByChanged: function (activatedBy) {
16+
Survey.JsonObject.metaData.addClass(
17+
"bootstrapdatepicker",
18+
[
19+
{ name: "inputType", visible: false },
20+
{ name: "inputFormat", visible: false },
21+
{ name: "inputMask", visible: false }
22+
],
23+
null,
24+
"text"
25+
);
26+
Survey.JsonObject.metaData.addProperty("bootstrapdatepicker", {
27+
name: "dateFormat"
28+
});
29+
},
30+
afterRender: function (question, el) {
31+
var $el = $(el).is(".widget-datepicker")
32+
? $(el)
33+
: $(el).find(".widget-datepicker");
34+
35+
var pickerWidget = $(".widget-datepicker").datepicker({
36+
enableOnReadonly: false
37+
})
38+
.on("changeDate", function (e) {
39+
question.value = moment(e.date).format("DD/MM/YYYY");
40+
// `e` here contains the extra attributes
41+
});
42+
43+
question.valueChangedCallback = function() {
44+
$(".widget-datepicker").datepicker('update', moment(question.value, "DD/MM/YYYY").toDate());
45+
}
46+
question.valueChangedCallback();
47+
question.readOnlyChangedCallback = function() {
48+
if(question.isReadOnly) {
49+
$el.prop('readonly', true);
50+
}
51+
else {
52+
$el.removeAttr('readonly');
53+
}
54+
}
55+
question.readOnlyChangedCallback();
56+
57+
},
58+
willUnmount: function (question, el) {
59+
var $el = $(el).is(".widget-datepicker")
60+
? $(el)
61+
: $(el).find(".widget-datepicker");
62+
$el.datepicker("destroy");
63+
question.readOnlyChangedCallback = undefined;
64+
question.valueChangedCallback = undefined;
65+
}
66+
};
67+
68+
Survey.CustomWidgetCollection.Instance.addCustomWidget(widget, "customtype");
69+
}
70+
71+
if (typeof Survey !== "undefined") {
72+
init(Survey, window.$);
73+
}
74+
75+
export default init;

0 commit comments

Comments
 (0)