input time redone to handle the hours as expected

This commit is contained in:
Gerard 2019-03-26 12:21:29 +01:00
parent 2ca5def095
commit f037fd8997
3 changed files with 31 additions and 25 deletions

View File

@ -6,7 +6,7 @@
<input <input
class="mdl-textfield__input" class="mdl-textfield__input"
type="time" type="time"
ng-model="$ctrl.model" ng-model="$ctrl.offsetedValue"
vn-validation="{{$ctrl.rule}}" vn-validation="{{$ctrl.rule}}"
ng-disabled="$ctrl.disabled" ng-disabled="$ctrl.disabled"
ng-readonly="$ctrl.readonly" ng-readonly="$ctrl.readonly"

View File

@ -3,37 +3,35 @@ import Textfield from '../textfield/textfield';
import './style.scss'; import './style.scss';
export default class InputTime extends Textfield { export default class InputTime extends Textfield {
set offsetedValue(value) {
this._offsetedValue = value;
let date = new Date(value);
let offset = date.getTimezoneOffset() * 60000;
date.setTime(date.getTime() - offset);
this._value = date;
}
get offsetedValue() {
return this._offsetedValue;
}
get value() { get value() {
return this._value; return this._value;
} }
get model() {
return this._model;
}
set model(value) {
this.value = value;
}
set value(value) { set value(value) {
if (!value) return; if (!value) return;
if (!this._offsetedValue) {
let newDate = new Date(value);
newDate.setSeconds(0);
newDate.setMilliseconds(0);
this._model = newDate;
this.hasValue = this._model !== null;
let date = new Date(value); let date = new Date(value);
date.setSeconds(0); date.setSeconds(0);
date.setMilliseconds(0); date.setMilliseconds(0);
let offset = date.getTimezoneOffset() * 60000; let offset = date.getTimezoneOffset() * 60000;
date.setTime(date.getTime() - offset); date.setTime(date.getTime() + offset);
this._value = date; this.offsetedValue = date;
}
this.hasValue = this._value !== null; this.hasValue = this._offsetedValue !== null;
if (this.hasValue) this.element.classList.add('not-empty'); if (this.hasValue) this.element.classList.add('not-empty');
@ -47,6 +45,13 @@ export default class InputTime extends Textfield {
set step(value) { set step(value) {
this.input.step = value; this.input.step = value;
} }
clear() {
this.saveOldValue();
this.offsetedValue = null;
if (this.onClear) this.onClear();
this.input.focus();
}
} }
InputTime.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude']; InputTime.$inject = ['$element', '$scope', '$attrs', 'vnTemplate', '$transclude'];

View File

@ -3,6 +3,7 @@
vn-textfield { vn-textfield {
margin: 20px 0!important; margin: 20px 0!important;
display: inline-block; display: inline-block;
width: 100%;
& > .container { & > .container {
width: 100%; width: 100%;