Skip to content

Commit

Permalink
Populate date fields with existing date if present
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart committed Oct 23, 2016
1 parent b2c6acd commit 76100c7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions public/assets/js/allcount.js
Expand Up @@ -54,6 +54,10 @@ allcountModule.config(["fieldRenderingServiceProvider", function (fieldRendering
return s && moment(s, 'YYYY-MM-DD HH:mm:ss').toDate();
}

function parseDateToMoment(s) {
return moment(s, "YYYY-MM-DD HH:mm:ss");
}

function wireTextInputWithController(input, controller, updateValue) {
input.val(controller.$viewValue);
input.on('input', function () {
Expand Down Expand Up @@ -154,7 +158,10 @@ allcountModule.config(["fieldRenderingServiceProvider", function (fieldRendering
locale: $locale.id.split("-")[0],
format: toMomentDateFormat(dateFormat(fieldDescription))
});
input.data("DateTimePicker").date(parseDate(controller.$viewValue) || null);
if(typeof controller.$viewValue != 'undefined') {
input.data("DateTimePicker").date(parseDate(controller.$viewValue) || null);
input.data("DateTimePicker").defaultDate(parseDateToMoment(controller.$viewValue) || null);
}
input.on('dp.change', function (e) {
updateValue(e.date ? e.date.format('YYYY-MM-DD HH:mm:ss') : undefined);
});
Expand Down Expand Up @@ -927,4 +934,4 @@ function toEntityCrudId(id) {
} else {
return id;
}
}
}

0 comments on commit 76100c7

Please sign in to comment.