vlio20 / angular-datepicker

Highly configurable date picker built for Angular applications
https://wondrous-crostata-172891.netlify.app/
MIT License
498 stars 142 forks source link

validator using old format #405

Closed ydg2018 closed 4 years ago

ydg2018 commented 6 years ago

i'm changing the used format after the page is done loading (example: DD-MM-YYYY to 00-MM-YYYY) and everything works like a charm except the validator. The validator keeps using the format i used at init.

the code in 'ng2-date-picker.js' that seems to use the wrong format is: return function (inputVal) { isValid = true; value = _this.convertToMomentArray(inputVal, format, true).filter(Boolean); if (!value.every(function (val) { return val.isValid(); })) { return { format: { given: inputVal } }; } var errors = validators.reduce(function (map, err) { if (!err.isValid()) { map[err.key] = { given: value }; } return map; }, {}); return !isValid ? errors : null; };

i change the config with the code below: this.datePicker.config = this.datePickerConfig; When i print this.datePicker.config.format it shows the new format and the input field displays the new date format correctly as well.

Did i miss something with the new format or is the validation part a bit bugged?

vlio20 commented 6 years ago

Hi @ydg2018 , sound very odd. Could you please create a stackblitz to easily reproduce your issue?

ydg2018 commented 6 years ago

here is a stackblitz: https://stackblitz.com/edit/datepickerformatissue i tried to make it the same as i use it, when you press toggle month the dp-date-picker element gets the class ng-invalid. The validator in the library seems to use the format that was given at the init of the component so that is still the same.

vlio20 commented 6 years ago

@ydg2018 I noticed you are accessing the config object directly within the date picker component: this.datePicker.config = this.datePickerConfig; you should never do that.

Please try to change the config object that you are passing to the config attribute of the component: this.datePickerConfig = this.datePickerConfig;

Let me know if it helps

ydg2018 commented 6 years ago

i changed the stackblitz to what you suggested but it didn't change the problem. Only thing i noticed was that the logging i had in the clickhandler printed the format before the change so i changed the logging a bit to see what it is at the moment of the click and what it should become.

nico281 commented 6 years ago

Hi, im running the same problem. im making a form builder and i need to change the format in a configuration but the changes to the config are not being reflected on the input. only after reload the page. there is a way to tell the directive to update the format? Cheers

vlio20 commented 6 years ago

I will take a look ASAP though there are some other things on the pipeline. If it's really urgent, consider reach via Fiverr.

vlio20 commented 4 years ago

I were able to reproduce the issue. Working on a fix

vlio20 commented 4 years ago

fixed in faa2d99 and will be available in 8.0.0