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
class="mdl-textfield__input"
type="time"
ng-model="$ctrl.model"
ng-model="$ctrl.offsetedValue"
vn-validation="{{$ctrl.rule}}"
ng-disabled="$ctrl.disabled"
ng-readonly="$ctrl.readonly"

View File

@ -3,37 +3,35 @@ import Textfield from '../textfield/textfield';
import './style.scss';
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() {
return this._value;
}
get model() {
return this._model;
}
set model(value) {
this.value = value;
}
set value(value) {
if (!value) return;
let newDate = new Date(value);
newDate.setSeconds(0);
newDate.setMilliseconds(0);
this._model = newDate;
this.hasValue = this._model !== null;
if (!this._offsetedValue) {
let date = new Date(value);
date.setSeconds(0);
date.setMilliseconds(0);
let offset = date.getTimezoneOffset() * 60000;
date.setTime(date.getTime() - offset);
this._value = date;
date.setTime(date.getTime() + offset);
this.offsetedValue = date;
}
this.hasValue = this._value !== null;
this.hasValue = this._offsetedValue !== null;
if (this.hasValue) this.element.classList.add('not-empty');
@ -47,6 +45,13 @@ export default class InputTime extends Textfield {
set 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'];

View File

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