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) {
this._model = value;
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);
this.modelView = this.$filter('date')(value, format);
}
@ -135,30 +136,36 @@ class DatePicker extends Component {
}
}
$onInit() {
if (!this.iniOptions)
this.iniOptions = {};
_getOptions() {
if (this.iniOptions) {
return this.iniOptions;
}
if (!this.iniOptions.locale)
this.iniOptions.locale = this.$translate.use();
let iniOptions = {};
if (!iniOptions.locale)
iniOptions.locale = this.$translate.use();
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 (!iniOptions.dateFormat && iniOptions.locale === 'es')
iniOptions.dateFormat = 'd-m-Y';
else if (iniOptions.dateFormat) {
let format = 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 ${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);
}
$onDestroy() {

View File

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