refactor dataPicker
This commit is contained in:
parent
ee7c4e214f
commit
76b5903770
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue