refactor dataPicker
This commit is contained in:
parent
ee7c4e214f
commit
76b5903770
|
@ -27,6 +27,7 @@ class DatePicker extends Component {
|
||||||
this.enabled = true;
|
this.enabled = true;
|
||||||
this._modelView = null;
|
this._modelView = null;
|
||||||
this._model = undefined;
|
this._model = undefined;
|
||||||
|
this._optionsChecked = false;
|
||||||
|
|
||||||
componentHandler.upgradeElement($element[0].firstChild);
|
componentHandler.upgradeElement($element[0].firstChild);
|
||||||
}
|
}
|
||||||
|
@ -137,30 +138,32 @@ class DatePicker extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
_getOptions() {
|
_getOptions() {
|
||||||
if (this.iniOptions) {
|
if (this.iniOptions && this._optionsChecked) {
|
||||||
return this.iniOptions;
|
return this.iniOptions;
|
||||||
|
} else if (!this.iniOptions) {
|
||||||
|
this.iniOptions = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
let iniOptions = {};
|
if (!this.iniOptions.locale)
|
||||||
if (!iniOptions.locale)
|
this.iniOptions.locale = this.$translate.use();
|
||||||
iniOptions.locale = this.$translate.use();
|
|
||||||
|
|
||||||
if (!iniOptions.dateFormat && iniOptions.locale === 'es')
|
if (!this.iniOptions.dateFormat && this.iniOptions.locale === 'es')
|
||||||
iniOptions.dateFormat = 'd-m-Y';
|
this.iniOptions.dateFormat = 'd-m-Y';
|
||||||
else if (iniOptions.dateFormat) {
|
else if (this.iniOptions.dateFormat) {
|
||||||
let format = iniOptions.dateFormat.split(/[ZT.,/ :-]/);
|
let format = this.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 ${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() {
|
$onInit() {
|
||||||
|
|
Loading…
Reference in New Issue