From b8f50b64dac53b2f61829fb287fe0bb36438cf7e Mon Sep 17 00:00:00 2001 From: Daniel Herrero Date: Wed, 13 Dec 2017 14:11:48 +0100 Subject: [PATCH] =?UTF-8?q?Componente=20datePicker=20a=C3=B1adido=20atribu?= =?UTF-8?q?to=20todate,=20(hoy=20como=20fecha=20por=20defecto)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../client/src/greuge-create/greuge-create.html | 2 +- client/core/src/datePicker/datePicker.js | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/client/client/src/greuge-create/greuge-create.html b/client/client/src/greuge-create/greuge-create.html index 9bc8830dd..d89891acd 100644 --- a/client/client/src/greuge-create/greuge-create.html +++ b/client/client/src/greuge-create/greuge-create.html @@ -11,7 +11,7 @@ Add Greuge - + diff --git a/client/core/src/datePicker/datePicker.js b/client/core/src/datePicker/datePicker.js index 26fba6c34..936eae2db 100644 --- a/client/core/src/datePicker/datePicker.js +++ b/client/core/src/datePicker/datePicker.js @@ -18,12 +18,15 @@ export const formatEquivalence = { }; class DatePicker extends Component { - constructor($element, $translate, $filter, $timeout) { + constructor($element, $translate, $filter, $timeout, $attrs, $scope) { super($element); this.input = $element[0].querySelector('input'); this.$translate = $translate; this.$filter = $filter; this.$timeout = $timeout; + this.$attrs = $attrs; + this.$scope = $scope; + this.enabled = true; this._modelView = null; this._model = undefined; @@ -168,6 +171,11 @@ class DatePicker extends Component { } ); } + + if (this.$attrs.hasOwnProperty('today')) { + this.iniOptions.defaultDate = new Date(); + } + this._optionsChecked = true; return this.iniOptions; } @@ -176,6 +184,9 @@ class DatePicker extends Component { this.iniOptions = this._getOptions(); this.isTimePicker = (this.iniOptions && this.iniOptions.enableTime && this.iniOptions.noCalendar); this.vp = new Flatpickr(this.input, this.iniOptions); + if (this.iniOptions.defaultDate) { + this.modelView = this.vp.formatDate(this.iniOptions.defaultDate, this.iniOptions.dateFormat); + } } destroyPicker() { if (this.vp) @@ -191,7 +202,7 @@ class DatePicker extends Component { this.destroyPicker(); } } -DatePicker.$inject = ['$element', '$translate', '$filter', '$timeout']; +DatePicker.$inject = ['$element', '$translate', '$filter', '$timeout', '$attrs', '$scope']; module.component('vnDatePicker', { template: require('./datePicker.html'),