Calendar not working well together with validators #2790
Labels
Type: Bug
Issue contains a bug related to a specific component. Something about the component is not working
Milestone
Hi,
I've been using Calendar component in an Angular Reactive Form and tried to add some validators to it. It all goes well until you try to validate if the user typed something that is a valid date or just left the input field empty. Calendar only returns null if date is not valid or field is empty, so you cannot distinguish between both cases (in my case, empty field is good, invalid value is not). I inspected the code and there is a property in Calendar named "filled" that should tell you if field has some content or not. That's great, I can use this property to determine if the field is empty, so I can do my validation. Problem comes in the moment you realize that validation code runs before this "filled" property gets updated with current value.
This is the code you have right now according to github:
There you can see that model of the component gets updated before "filled" property gets updated with good value. So in my code I had overridden the method just exchanging last two lines of the method:
This way "filled" has the updated value and can be used to validate field is empty. I would prefer to have some method to check status of the field instead of relying directly on the property, but I leave that decision to you.
I will submit a PR with my proposed fix for you to consider.
Also created same issue on the forum:
https://forum.primefaces.org/viewtopic.php?f=35&t=50922
Thanks.
The text was updated successfully, but these errors were encountered: