fomantic / Fomantic-UI

Fomantic-UI is the official community fork of Semantic-UI
https://fomantic-ui.com
MIT License
3.55k stars 331 forks source link

[form validation] keyHeldDown conflicting behavior #3012

Open alvarolm opened 7 months ago

alvarolm commented 7 months ago

Bug Report

the use of keyHeldDown together with the "validate form" behavior is not compatible, as (the behavior) when called externally: $(elem).form("validate form") has no key interaction, in fact, it should not consider keyHeldDown when called in this manner.

lubber-de commented 7 months ago

keyHeldDown is false by default and only gets set to true whenever a key is actually, well, held down ;) (it gets false again when key is released) So, when calling the "validate form" behavior (and no key is kept pressed down), this won't affect the form validation. That said i don't see an issue here which we would need to fix.

If i misunderstood or dont understand, please provide a jsfiddle explaining your use case where we can reproduce the need of a change.

alvarolm commented 7 months ago

the mechanic to release the "hold" state its not atomic and may be intercepted or canceled by others events

https://github.com/fomantic/Fomantic-UI/blob/develop/src/definitions/behaviors/form.js#L442C49-L442C54

I have resorted to disable keyboardShortcuts and re-implement the desired behavior myself

lubber-de commented 7 months ago

The mentioned code only applies when the enter key is pressed inside an input to prevent double form submit. In all other cases the keyHeldDown is kept false. I get your point, but i cannot imagine a use case where the onetime keyup event will not trigger or you call "validate form" in between those special events and use case. I always feel preventing the double submit is more of priority. In doubt, you could check for a pressed key yourself before calling validate form to double check if the "false" response from the behavior is caused by the keyHeldDown variable. Perhaps this is what you already did now (?)

That said, i actually don't know how/what to change in the FUI core without a proper testcase which illustrates the bug. So, if possible, please share some jsfiddle :)