Skip to content

Commit 6bb7636

Browse files
author
T_S_V
committed
Implemented culture for jQuery date picker
1 parent ff1220f commit 6bb7636

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/jquery-ui-datepicker.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
function init(Survey, $) {
2+
23
$ = $ || window.$;
34
if (!$.fn.bootstrapDP && !!$.fn.datepicker && !!$.fn.datepicker.noConflict) {
45
$.fn.bootstrapDP = $.fn.datepicker.noConflict();
@@ -35,6 +36,33 @@ function init(Survey, $) {
3536
name: "config",
3637
default: null
3738
});
39+
Survey.JsonObject.metaData.addProperty("datepicker", {
40+
name: "dateSeparator",
41+
choices: function(obj) {
42+
return Survey.cultureInfo && Survey.cultureInfo.getCulture(obj && obj.culture).dateSeparators || [];
43+
},
44+
onSetValue: function(obj, value, jsonConv) {
45+
var newValue = value || "/";
46+
if(!!obj.shortDateFormat) {
47+
var regex = new RegExp(obj.dateSeparator, 'g');
48+
obj.shortDateFormat = obj.shortDateFormat.replace(regex, newValue);
49+
}
50+
obj.setPropertyValue("dateSeparator", newValue);
51+
},
52+
default: "/"
53+
});
54+
Survey.JsonObject.metaData.addProperty("datepicker", {
55+
name: "shortDateFormat",
56+
dependsOn: "dateSeparator",
57+
choices: function(obj) {
58+
return (Survey.cultureInfo && Survey.cultureInfo.getCulture(obj && obj.culture).shortDateFormats || []).map(function(fmt) {
59+
return {
60+
text: fmt.text.replace(/\//g, obj.dateSeparator || "/"),
61+
value: fmt.value.replace(/\//g, obj.dateSeparator || "/")
62+
}
63+
});
64+
}
65+
});
3866
},
3967
afterRender: function(question, el) {
4068
var $el = $(el).is(".widget-datepicker")
@@ -50,6 +78,11 @@ function init(Survey, $) {
5078
config.dateFormat = !!question.dateFormat
5179
? question.dateFormat
5280
: undefined;
81+
if (config.dateFormat === undefined) {
82+
config.dateFormat = !!question.shortDateFormat
83+
? question.shortDateFormat
84+
: undefined;
85+
}
5386
}
5487
if (config.option === undefined) {
5588
config.option = {

0 commit comments

Comments
 (0)