lucaswerkmeister / tool-lexeme-forms

Wikidata tool to create lexemes with pre-populated forms (e. g. declensions or conjugations)
https://lexeme-forms.toolforge.org/
Other
11 stars 7 forks source link

Pressing Enter in normal mode edits first listed duplicates if any duplicate warnings are present #11

Closed lucaswerkmeister closed 3 years ago

lucaswerkmeister commented 3 years ago

When the tool warns the user of potential duplicate lexemes for their input –

The following existing lexeme has the same lemma and language code as the one you’re trying to create:

  • example (L2237), English, noun, 2 forms and one sense (edit)

If you’re sure that it’s different, check the box at the bottom of the form.

– the “edit” element, which looks like a link, is actually a button (since 8d5f428c3e0822bc82584b961585db410d3ca79e). This means when the user clicks it, all the form inputs get submitted to the server, so that the server can use them to populate the edit mode fields already, instead of discarding the user’s input. That’s supposed to be a feature :)

However, this also means that the “edit” “link” of the first potential duplicate is also the default button of the form, if it exists, and therefore pressing Enter in the form (after checking the “not a duplicate” checkbox) will actually submit that button, and send the user to edit mode, rather than submitting the form with the “create” button and creating the lexeme as the user probably wanted.

There doesn’t seem to be a good way to prevent this. HTML has no way to set a different default button, it’s always the form’s first submit button in tree order. (For the feature to work, especially without JS, it does need to be a submit button, and it does need to have that form as the form owner.) We could put the duplicates warning after the rest of the form in tree order, and swap it back up with flex-direction: column-reverse, but that puts the duplicates warning after the rest of the form for screen readers. We could insert an invisible copy of the “create” button before the duplicates warning, but it would still be part of the tab order and also probably be shown to screen readers. (Credit for these ideas goes to this StackOverflow question, though I won’t be using any of these techniques.)

No, I think the best solution is to not make the link a button at all, but rather a regular link. If JS is enabled, then we can add ?form_representation=X&form_representation=... to the URL in a click handler, using the current values of the inputs. If JS is not enabled, we can’t add the current input values, but in that case the duplicates warning is only shown after the form was submitted to the server anyways, so we can add the submitted values to the link server-side, and speculate that the user won’t edit the inputs again before clicking the link.