rjaros / kvision

Object oriented web framework for Kotlin/JS
https://kvision.io
MIT License
1.2k stars 67 forks source link

The onEvent callback for keydown for single field forms is not working properly. #472

Closed pambrose closed 1 year ago

pambrose commented 1 year ago

Single field forms are not working properly. If a form has more than one field, the onEvent{} for keydown is called as expected. However, if a form has only one field, the onEvent{} for keydown is not called and the page is instead reloaded.

In order to see the issue, please clone this repo https://github.com/pambrose/kvision-issues and run the app.

Thanks, Paul

rjaros commented 1 year ago

Hello, This is not KVision issue. This is a know browsers bug, originating from HTML 2.0 specification (1995!). Here you an find some more datails: https://stackoverflow.com/questions/1370021/why-does-forms-with-single-input-field-submit-upon-pressing-enter-key-in-input Probably the easiest workaround when using FormPanel with only one field is to add onsubmit attribute:

formPanel {
    setAttribute("onsubmit", "return false;")
    // ...
}
pambrose commented 1 year ago

Thanks!