mymth / vanillajs-datepicker

A vanilla JavaScript remake of bootstrap-datepicker for Bulma and other CSS frameworks
MIT License
742 stars 153 forks source link

Don't swallow enter on collapsed datepicker #88

Closed henkesn closed 2 years ago

henkesn commented 2 years ago

First of all: Thank you for sharing this great project!

Currently, the datepicker objects listens on the keydown event including preventDefault: https://github.com/mymth/vanillajs-datepicker/blob/9de5051545626b116db3d213b0b1e429f296967c/js/events/inputFieldListeners.js#L86.

In a form with a bunch of inputs, it feels a bit inconsistent/clumsy, that some fields (non-datepicker fields) submit on enter and datepicker fields dont, especially when the datepicker input has not been changed.

mymth commented 2 years ago

Throughout my experience, submitting a form by hitting enter on an input field has always been a thing needs to be prevented. So I was unable to imagine this could be an issue. Could you please give me some more examples? I'd like to look deeper into this.

henkesn commented 2 years ago

Thanks for your reply! I think, preventing enter form submission really depends on the actual use case and is not in the datepicker's responsability. If you need to prevent it on a complex form, you need a concept for non date fields anyway. Some examples, where enter can be very comfortable:

mymth commented 2 years ago

I was actually expecting to see other examples than implicit submission, but it's not important now. I admit I was lazy simplifying the event cancellation without thinking well why bootstrap-datepicker does it in some cases but not in other cases. There shouldn't be restrictions without reason.

I'll review the cases and remove unnecessary cancellations. Thanks for the suggestion.