Componente datePicker añadido atributo todate, (hoy como fecha por defecto)

This commit is contained in:
Daniel Herrero 2017-12-13 14:11:48 +01:00
parent 9fe0aadff8
commit b8f50b64da
2 changed files with 14 additions and 3 deletions

View File

@ -11,7 +11,7 @@
<vn-title vn-one margin-large-bottom>Add Greuge</vn-title> <vn-title vn-one margin-large-bottom>Add Greuge</vn-title>
<vn-horizontal> <vn-horizontal>
<vn-textfield vn-one margin-medium-right label="Importe" field="$ctrl.greuge.amount" type="number" vn-focus></vn-textfield> <vn-textfield vn-one margin-medium-right label="Importe" field="$ctrl.greuge.amount" type="number" vn-focus></vn-textfield>
<vn-date-picker vn-one label="Date" model="$ctrl.greuge.shipped"></vn-date-picker> <vn-date-picker vn-one label="Date" model="$ctrl.greuge.shipped" today></vn-date-picker>
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-textfield vn-one margin-medium-right label="Comment" field="$ctrl.greuge.description"></vn-textfield> <vn-textfield vn-one margin-medium-right label="Comment" field="$ctrl.greuge.description"></vn-textfield>

View File

@ -18,12 +18,15 @@ export const formatEquivalence = {
}; };
class DatePicker extends Component { class DatePicker extends Component {
constructor($element, $translate, $filter, $timeout) { constructor($element, $translate, $filter, $timeout, $attrs, $scope) {
super($element); super($element);
this.input = $element[0].querySelector('input'); this.input = $element[0].querySelector('input');
this.$translate = $translate; this.$translate = $translate;
this.$filter = $filter; this.$filter = $filter;
this.$timeout = $timeout; this.$timeout = $timeout;
this.$attrs = $attrs;
this.$scope = $scope;
this.enabled = true; this.enabled = true;
this._modelView = null; this._modelView = null;
this._model = undefined; this._model = undefined;
@ -168,6 +171,11 @@ class DatePicker extends Component {
} }
); );
} }
if (this.$attrs.hasOwnProperty('today')) {
this.iniOptions.defaultDate = new Date();
}
this._optionsChecked = true; this._optionsChecked = true;
return this.iniOptions; return this.iniOptions;
} }
@ -176,6 +184,9 @@ class DatePicker extends Component {
this.iniOptions = this._getOptions(); this.iniOptions = this._getOptions();
this.isTimePicker = (this.iniOptions && this.iniOptions.enableTime && this.iniOptions.noCalendar); this.isTimePicker = (this.iniOptions && this.iniOptions.enableTime && this.iniOptions.noCalendar);
this.vp = new Flatpickr(this.input, this.iniOptions); this.vp = new Flatpickr(this.input, this.iniOptions);
if (this.iniOptions.defaultDate) {
this.modelView = this.vp.formatDate(this.iniOptions.defaultDate, this.iniOptions.dateFormat);
}
} }
destroyPicker() { destroyPicker() {
if (this.vp) if (this.vp)
@ -191,7 +202,7 @@ class DatePicker extends Component {
this.destroyPicker(); this.destroyPicker();
} }
} }
DatePicker.$inject = ['$element', '$translate', '$filter', '$timeout']; DatePicker.$inject = ['$element', '$translate', '$filter', '$timeout', '$attrs', '$scope'];
module.component('vnDatePicker', { module.component('vnDatePicker', {
template: require('./datePicker.html'), template: require('./datePicker.html'),