Skip to content

Commit f3a062b

Browse files
committed
Support readonly/computed for dates #207
1 parent a183be4 commit f3a062b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

grails-app/assets/javascripts/knockout-dates.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,26 @@
6969
// a JS Date object - useful with datepicker; and
7070
// a simple formatted date of the form dd-mm-yyyy useful for display.
7171
// The formatted date will include hh:MM if the includeTime argument is true
72-
ko.extenders.simpleDate = function (target, includeTime) {
72+
ko.extenders.simpleDate = function (target, options) {
73+
var includeTime = false;
74+
var isReadOnly = false;
75+
if (_.isObject(options)) {
76+
includeTime = options.includeTime || false;
77+
isReadOnly = options.readOnly || false;
78+
}
79+
else {
80+
includeTime = options || false;
81+
}
82+
7383
target.date = ko.computed({
7484
read: function () {
7585
return Date.fromISO(target());
7686
},
7787

7888
write: function (newValue) {
89+
if (isReadOnly) {
90+
return;
91+
}
7992
if (newValue) {
8093
var current = target(),
8194
valueToWrite = convertToIsoDate(newValue);
@@ -95,6 +108,9 @@
95108
},
96109

97110
write: function (newValue) {
111+
if (isReadOnly) {
112+
return;
113+
}
98114
if (newValue) {
99115
var current = target(),
100116
valueToWrite = convertToIsoDate(newValue);

0 commit comments

Comments
 (0)