bug fixed in dataPicker

This commit is contained in:
Daniel Herrero 2017-10-31 09:44:24 +01:00
parent bec05a1925
commit ee7c4e214f
2 changed files with 26 additions and 13 deletions

View File

@ -37,7 +37,8 @@ class DatePicker extends Component {
set model(value) { set model(value) {
this._model = value; this._model = value;
if (value && !this.modelView) { if (value && !this.modelView) {
let initialDateFormat = (this.iniOptions && this.iniOptions.dateFormat) ? this.iniOptions.dateFormat : 'Y-m-d'; let options = this._getOptions();
let initialDateFormat = (options && options.dateFormat) ? options.dateFormat : 'Y-m-d';
let format = this._formatFlat2Angular(initialDateFormat); let format = this._formatFlat2Angular(initialDateFormat);
this.modelView = this.$filter('date')(value, format); this.modelView = this.$filter('date')(value, format);
} }
@ -135,30 +136,36 @@ class DatePicker extends Component {
} }
} }
$onInit() { _getOptions() {
if (!this.iniOptions) if (this.iniOptions) {
this.iniOptions = {}; return this.iniOptions;
}
if (!this.iniOptions.locale) let iniOptions = {};
this.iniOptions.locale = this.$translate.use(); if (!iniOptions.locale)
iniOptions.locale = this.$translate.use();
if (!this.iniOptions.dateFormat && this.iniOptions.locale === 'es') if (!iniOptions.dateFormat && iniOptions.locale === 'es')
this.iniOptions.dateFormat = 'd-m-Y'; iniOptions.dateFormat = 'd-m-Y';
else if (this.iniOptions.dateFormat) { else if (iniOptions.dateFormat) {
let format = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/); let format = iniOptions.dateFormat.split(/[ZT.,/ :-]/);
if (format.length <= 1) { if (format.length <= 1) {
throw new Error(`Error: Invalid string format ${format}`); throw new Error(`Error: Invalid string format ${format}`);
} }
format.forEach( format.forEach(
val => { val => {
if (!formatEquivalence[val]) { if (!formatEquivalence[val]) {
throw new Error(`Error in dateFormat ${this.iniOptions.dateFormat}: is not like Flatpickr Formatting Token https://chmln.github.io/flatpickr/formatting/`); throw new Error(`Error in dateFormat ${iniOptions.dateFormat}: is not like Flatpickr Formatting Token https://chmln.github.io/flatpickr/formatting/`);
} }
} }
); );
} }
return iniOptions;
}
$onInit() {
this.iniOptions = this._getOptions();
if (this.input)
this.vp = new Flatpickr(this.input, this.iniOptions); this.vp = new Flatpickr(this.input, this.iniOptions);
} }
$onDestroy() { $onDestroy() {

View File

@ -1,3 +1,9 @@
<vn-watcher
vn-id="watcher"
data="$ctrl.route"
form="form"
>
</vn-watcher>
<form name="form" pad-medium> <form name="form" pad-medium>
<vn-card> <vn-card>
<vn-vertical pad-large> <vn-vertical pad-large>