thewca / worldcubeassociation.org

All of the code that runs on worldcubeassociation.org
https://www.worldcubeassociation.org/
GNU General Public License v3.0
335 stars 177 forks source link

Typing enter while entering a cut-off ignores the input #10172

Open kr-matthews opened 3 weeks ago

kr-matthews commented 3 weeks ago

Describe the bug When editing a cutoff in a competition's edit events form, typing a time followed by enter will ignore the time and close the modal with the old value still in use (0 if there was no old value).

To Reproduce Steps to reproduce the behavior:

  1. Go to a competition you're organizing/delegating and go to Edit > Manage Events
  2. Add an event, add a round for that event, click on the "-" box to edit the cutoff.
  3. Select Best of 2 and type something into the result box.
  4. Type enter.
  5. The modal closes and 0 is used as the cutoff result, ignoring the time you had typed.

Expected behavior Enter should use the time and close the modal.

Additional Context There are a lot of modals on this page, make sure they all work properly when typing enter in any input.

kr-matthews commented 3 weeks ago

I'm not sure how to fix this. The TimeField (the input) has a draftInput value which isn't passed on to the actual value until the input is blurred (because you might want to type 60000 for 6:00.00, but after the first 4 keys the input is 6000 which can't be parsed to a valid time). Pressing enter submits the modal, which causes the time field to be removed before it has a chance to use the draft input value.

Disabling enter (by removing the onSubmit from the modal and adding the handling to the modal button instead) would prevent people from accidentally losing the value they typed, but would be annoying - and this modal is used elsewhere too so that might have other consequences.