bug fixed in new datepicker and material design label effect

This commit is contained in:
Dani Herrero 2017-07-13 11:03:22 +02:00
parent a06ac62b91
commit 7dfed60e7d
1 changed files with 33 additions and 20 deletions

View File

@ -27,34 +27,34 @@ class DatePicker extends Component {
this.enabled = true;
this._modelView = '';
this._model = undefined;
componentHandler.upgradeElement($element[0].firstChild);
}
get model() {
return this._model;
}
set model(value) {
this._model = value;
if (value && !this.modelView) {
let format = this._formatFlat2Angular(this.iniOpts.dateFormat || 'Y-m-d');
let format = this._formatFlat2Angular(this.iniOptions.dateFormat || 'Y-m-d');
this.modelView = this.$filter('date')(value, format);
}
}
get modelView() {
return this._modelView;
}
set modelView(value) {
this._modelView = value;
this.input.value = value;
this._setModel(value);
this.$timeout(
() => {
this.mdlUpdate();
}
);
() => {
this.mdlUpdate();
}, 500);
}
onClear() {
this.modelView = '';
this.modelView = null;
}
mdlUpdate() {
let mdlField = this.element.firstChild.MaterialTextfield;
@ -63,7 +63,7 @@ class DatePicker extends Component {
}
_formatFlat2Angular(string) { // change string Flatpickr format to angular format (d-m-Y -> dd-MM-yyyy)
let aux = string.split((/[ZT.,/ :-]/));
let aux = string.split(/[ZT.,/ :-]/);
let parts = [];
aux.forEach(
val => {
@ -85,11 +85,11 @@ class DatePicker extends Component {
let model;
if (!value) {
model = undefined;
} else if (!this.iniOpts.dateFormat || (this.iniOpts.dateFormat && this.iniOpts.dateFormat.startsWith('Y-m-d'))) {
} else if (!this.iniOptions.dateFormat || (this.iniOptions.dateFormat && this.iniOptions.dateFormat.startsWith('Y-m-d'))) {
model = value;
} else {
let formats = this.iniOpts.dateFormat.split((/[ZT.,/ :-]/));
let aux = value.split((/[ZT.,/ :-]/));
let formats = this.iniOptions.dateFormat.split(/[ZT.,/ :-]/);
let aux = value.split(/[ZT.,/ :-]/);
let date = {};
formats.forEach(
(k, i) => {
@ -137,17 +137,30 @@ class DatePicker extends Component {
}
$onInit() {
if (!this.iniOpts)
this.iniOpts = {};
if (!this.iniOptions)
this.iniOptions = {};
if (!this.iniOpts.locale)
this.iniOpts.locale = this.$translate.use();
if (!this.iniOptions.locale)
this.iniOptions.locale = this.$translate.use();
if (!this.iniOpts.dateFormat && this.iniOpts.locale === 'es')
this.iniOpts.dateFormat = 'd-m-Y';
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 (!fromatEquivalence[val]) {
throw new Error(`Error in dateFormat ${this.iniOptions.dateFormat}: is not like Flatpickr Formatting Token https://chmln.github.io/flatpickr/formatting/`);
}
}
);
}
if (this.input)
this.vp = new Flatpickr(this.input, this.iniOpts);
this.vp = new Flatpickr(this.input, this.iniOptions);
}
$onDestroy() {
if (this.vp)
@ -164,7 +177,7 @@ module.component('vnDatePicker', {
name: '@?',
enabled: '<?',
rule: '<?',
iniOpts: '<?'
iniOptions: '<?'
},
controller: DatePicker
});