fix issue with date not updating properly

This commit is contained in:
Mads Rasmussen
2016-12-21 13:00:45 +01:00
parent 219f855d86
commit aa5ad746eb
3 changed files with 18 additions and 22 deletions

View File

@@ -16,7 +16,6 @@ Use this directive to render a date time picker
<umb-date-time-picker
options="vm.config"
ng-model="vm.date"
on-change="vm.datePickerChange(event)"
on-error="vm.datePickerError(event)">
</umb-date-time-picker>
@@ -53,6 +52,9 @@ Use this directive to render a date time picker
function datePickerChange(event) {
// handle change
if(event.date && event.date.isValid()) {
var date = event.date.format(vm.datePickerConfig.format);
}
}
function datePickerError(event) {
@@ -67,7 +69,6 @@ Use this directive to render a date time picker
</pre>
@param {object} options (<code>binding</code>): Config object for the date picker.
@param {string} ngModel (<code>binding</code>): Date value.
@param {callback} onHide (<code>callback</code>): Hide callback.
@param {callback} onShow (<code>callback</code>): Show callback.
@param {callback} onChange (<code>callback</code>): Change callback.
@@ -114,8 +115,6 @@ Use this directive to render a date time picker
function onChange(event) {
if (scope.onChange && event.date && event.date.isValid()) {
scope.$apply(function(){
// Update ngModel
scope.ngModel = event.date.format(scope.options.format);
// callback
scope.onChange({event: event});
});
@@ -143,7 +142,7 @@ Use this directive to render a date time picker
function initDatePicker() {
// Open the datepicker and add a changeDate eventlistener
element
.datetimepicker(angular.extend({ useCurrent: true }, scope.options))
.datetimepicker(scope.options)
.on("dp.hide", onHide)
.on("dp.show", onShow)
.on("dp.change", onChange)
@@ -160,7 +159,6 @@ Use this directive to render a date time picker
replace: true,
templateUrl: 'views/components/umb-date-time-picker.html',
scope: {
ngModel: "=",
options: "=",
onHide: "&",
onShow: "&",

View File

@@ -12,13 +12,7 @@
vm.datePickerConfig = {
pickDate: true,
pickTime: false,
format: "YYYY-MM-DD",
icons: {
time: "icon-time",
date: "icon-calendar",
up: "icon-chevron-up",
down: "icon-chevron-down"
}
format: "YYYY-MM-DD"
};
vm.query = {
@@ -147,16 +141,28 @@
function setFilterProperty(filter, property) {
filter.property = property;
filter.term = {};
filter.constraintValue = "";
}
function setFilterTerm(filter, term) {
filter.term = term;
if(filter.constraintValue) {
throttledFunc();
}
}
function changeConstraintValue() {
throttledFunc();
}
function datePickerChange(event, filter) {
if(event.date && event.date.isValid()) {
filter.constraintValue = event.date.format(vm.datePickerConfig.format);
throttledFunc();
}
}
var throttledFunc = _.throttle(function () {
templateQueryResource.postTemplateQuery(vm.query)
@@ -166,13 +172,6 @@
}, 200);
function datePickerChange(event) {
templateQueryResource.postTemplateQuery(vm.query)
.then(function (response) {
$scope.model.result = response;
});
}
onInit();
}

View File

@@ -72,8 +72,7 @@
<span ng-show="filter.term.appliesTo[0] === 'datetime'">
<umb-date-time-picker
options="vm.datePickerConfig"
ng-model="filter.constraintValue"
on-change="vm.datePickerChange()">
on-change="vm.datePickerChange(event, filter)">
</umb-date-time-picker>
</span>