refactor dataPicker

This commit is contained in:
Daniel Herrero 2017-10-31 10:40:12 +01:00
parent ee7c4e214f
commit 76b5903770
1 changed files with 13 additions and 10 deletions

View File

@ -27,6 +27,7 @@ class DatePicker extends Component {
this.enabled = true;
this._modelView = null;
this._model = undefined;
this._optionsChecked = false;
componentHandler.upgradeElement($element[0].firstChild);
}
@ -137,30 +138,32 @@ class DatePicker extends Component {
}
_getOptions() {
if (this.iniOptions) {
if (this.iniOptions && this._optionsChecked) {
return this.iniOptions;
} else if (!this.iniOptions) {
this.iniOptions = {};
}
let iniOptions = {};
if (!iniOptions.locale)
iniOptions.locale = this.$translate.use();
if (!this.iniOptions.locale)
this.iniOptions.locale = this.$translate.use();
if (!iniOptions.dateFormat && iniOptions.locale === 'es')
iniOptions.dateFormat = 'd-m-Y';
else if (iniOptions.dateFormat) {
let format = iniOptions.dateFormat.split(/[ZT.,/ :-]/);
if (!this.iniOptions.dateFormat && this.iniOptions.locale === 'es')
this.iniOptions.dateFormat = 'd-m-Y';
else if (this.iniOptions.dateFormat) {
let format = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/);
if (format.length <= 1) {
throw new Error(`Error: Invalid string format ${format}`);
}
format.forEach(
val => {
if (!formatEquivalence[val]) {
throw new Error(`Error in dateFormat ${iniOptions.dateFormat}: is not like Flatpickr Formatting Token https://chmln.github.io/flatpickr/formatting/`);
throw new Error(`Error in dateFormat ${this.iniOptions.dateFormat}: is not like Flatpickr Formatting Token https://chmln.github.io/flatpickr/formatting/`);
}
}
);
}
return iniOptions;
this._optionsChecked = true;
return this.iniOptions;
}
$onInit() {