Skip to content

IQSS/dataverse#7895 prevent clearing fields in dataset form when hitting enter#8488

Closed
haarli wants to merge 4 commits intoIQSS:developfrom
MPDL:IQSS/7895_hitting_enter_in_dataset_form
Closed

IQSS/dataverse#7895 prevent clearing fields in dataset form when hitting enter#8488
haarli wants to merge 4 commits intoIQSS:developfrom
MPDL:IQSS/7895_hitting_enter_in_dataset_form

Conversation

@haarli
Copy link
Contributor

@haarli haarli commented Mar 15, 2022

This pull request closes #7895.
It adds a dummy button with no functionality to the beginning of the dataset form. This way, when pressing enter in a single text field of the form, nothing happens. Before, all fields in the form were cleared, which is an undesired behaviour.

@sekmiller sekmiller self-assigned this Mar 16, 2022
Copy link
Contributor

@sekmiller sekmiller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a good approach and I've found that it works for Chrome and Firefox, but it doesn't work for Safari. A quick look on my part didn't yield a solution for Safari.

@haarli
Copy link
Contributor Author

haarli commented Mar 16, 2022

Thanks for the review, didn't check with Safari.

Safari seems to ignore submit buttons with "display=none" when it comes to hitting the enter button inside the form (same goes for buttons with the HTML5 attribute "hidden"). Firefox and Chrome do not.

So even without this PR, there's currently a different behaviour when hitting enter in any single-line text field in the datasetForm. And there's also a difference between creating a new dataset and editing:

Current behaviour

  • Create a new dataset:
    • Firefox/Chrome:
      All input is cleared, because the hidden button for changing the owner dataverse is internally fired (As it is the first submit button inside the form)
    • Safari:
      The "Save"-button is fired, as all other submit buttons are hidden via "display:none"
  • Edit dataset metadata:
    Here, a save button is additionally displayed at the top of the form. So this one is always fired, independent of the browser.

Behaviour with PR

Clearing all input is worst case. So with this PR, in Firefox and Chrome nothing would happen when pressing enter (for create and edit). In Safari, "save" would be triggered (for create and edit).
Not perfect at all and still inconsistent, but maybe better than the current situation (clearing all fields).

@sekmiller
Copy link
Contributor

I found this bit of jquery which seems to work on Firefox, Chrome and Safari: $(document).on("keydown", "form", function(event) { return event.key !== "Enter"; });

@haarli
Copy link
Contributor Author

haarli commented Mar 17, 2022

The problem with this JS snippet is that it prevents any usage of the enter button in the form, e.g. newlines in the description field wouldn't be possible anymore.

@ErykKul
Copy link
Collaborator

ErykKul commented Mar 17, 2022

I was thinking about this solution: #8500
I think it should disable enter only where it is needed.

@haarli
Copy link
Contributor Author

haarli commented Mar 18, 2022

Thanks for the alternative solution. Looks good.

@sekmiller
Copy link
Contributor

I'm going to close this in favor of Erik's solution. Thanks for your contribution.

@sekmiller sekmiller closed this Mar 21, 2022
@sekmiller sekmiller removed their assignment Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hitting enter in text fields triggers metadata form save

3 participants