Skip to content

SectorNordAG: Pressing 'Enter' key inside of <input> triggers wrong event in AgentTicketNote.#554

Open
ZTrotter wants to merge 7 commits intoznuny:devfrom
SectorNordAG:dev-AgentTicketNote_Redirect
Open

SectorNordAG: Pressing 'Enter' key inside of <input> triggers wrong event in AgentTicketNote.#554
ZTrotter wants to merge 7 commits intoznuny:devfrom
SectorNordAG:dev-AgentTicketNote_Redirect

Conversation

@ZTrotter
Copy link
Contributor

@ZTrotter ZTrotter commented Apr 8, 2024

Proposed change

On a page with both Save as new draft and Submit buttons, pressing the Enter key inside a element triggers the Save as new draft button by default.

In order to fix this behaviour, the following code could be added to Core.Form.js.

    $('body').on('keydown', 'input', function (Event) {
        if (Event.keyCode == 13 && $(this).closest('form').find(':submit').length > 0) {
            Event.preventDefault();
            $(this.form).find(':submit').last().click();
        }
    });

Additionally, the code that handles the user attempting to submit a form from within a <textarea> when Frontend::RichText is disabled could be updated to similarly trigger the expected button by changing the logic of how the button is selected. Currently it selects the first element with the type submit, which it mistakenly believes to be Save as new draft, changing this to last() instead will trigger the expected button.

    $('body').on('keydown', 'textarea', function (Event) {
        if ((Event.ctrlKey || Event.metaKey) && Event.keyCode == 13) {
            // We need to click() instead of submit(), since click() has
            // a few useful event handlers tied to it, like validation.
            Event.preventDefault();
            $(this.form).find(':submit').last().click();
        }
    });

Type of change

1 - 🐞 bug 🐞

Additional information

  • Navigate to AgentTicketZoom
  • Click on Communication and select Note
  • Enter some dummy information in both Subject and Text, click inside of Subject and click Enter
  • You will be presented with the Add new draft popup instead of the form submitting

Checklist

  • The code change is tested and works locally.(❗)
  • There is no commented out code in this PR.(❕)
  • You improved or added new unit tests.(❕)
  • Local ZnunyCodePolicy passed.(❕)
  • Local UnitTests / Selenium passed.(❕)
  • GitHub workflow CI (UnitTests / Selenium) passed.(❗)

@dennykorsukewitz
Copy link
Member

Hi @ZTrotter

This branch has conflicts that must be resolved
Can you please resolve the conflicts.

@rkaldung Can you briefly verify / qa this again?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

The save button is not the standard submit button

2 participants