Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from

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.(❗)

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.

1 participant