I wrote this custom component:
<datetime value="vm.woComplete.CompleteDate" max="2016-10-25"></datetime>
max attribute doesnt work as it should in html5 validation date input.
Why?
// DateTimeComponent is used for date/time input with 2-way binding and UTC correction
namespace AppDomain {
"use strict";
class DateTimeController {
value: Date;
displayValue: Date;
max: string;
static $inject = ["$scope"];
// West from UTC - TimezoneOffset is positive , East from UTC - TimezoneOffset is negative
constructor($scope: ng.IScope) {
$scope.$watch(
"$ctrl.displayValue",
(newValue: Date, oldValue: Date) => {
this.value = newValue;
var offset = this.displayValue.getTimezoneOffset() / 60; // getTimezoneOffset returns minutes, we need hours
this.value.setHours(this.value.getHours() + offset); // LOCAL to UTC = UTC + Offset
}
);
}
$onInit() {
this.displayValue = this.value;
var offset = this.displayValue.getTimezoneOffset() / 60; // getTimezoneOffset returns minutes, we need hours
this.displayValue.setHours(this.displayValue.getHours() - offset); // UTC to LOCAL = UTC - Offset
}
}
const DateTimeComponent: ng.IComponentOptions = {
//template: "<p><input type='date' class='form-control' ng-model='$ctrl.displayValue'></p><p><input type='time' class='form-control' ng-model='$ctrl.displayValue'></p>",
template: "<p><input type='datetime-local' class='form-control' ng-model='$ctrl.displayValue' max='{{$ctrl.max}}'></p>",
bindings: {
value: "=",
max: "@"
},
controller: DateTimeController
};
angular.module("app").component("datetime", DateTimeComponent);
}