znuny / Znuny

Znuny/Znuny LTS is a fork of the ((OTRS)) Community Edition, one of the most flexible web-based ticketing systems used for Customer Service, Help Desk, IT Service Management.
https://www.znuny.org
GNU General Public License v3.0
367 stars 86 forks source link

SectorNordAG: Clicking 'Enter' inside of <input> triggers wrong event. #498

Closed ZTrotter closed 7 months ago

ZTrotter commented 1 year ago

Proposed change

On a page with both Save as new draft and Submit buttons, clicking the Enter key inside a <input> box triggers the Save as new draft button by default. This behaviour is not consistent with the same pages in Znuny6.

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

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

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.
            $(this.form).find(':submit').last().click();
        }
        Event.preventDefault()
    });

Type of change

'1 - 🐞 bug 🐞'

Additional information

Replication

Checklist

NiklasSchmitt commented 8 months ago

It seems for me that your code is not working correctly. Tested on AgentTicketNote with disabled Frontend::RichText.

jepf commented 6 months ago

@ZTrotter

Unfortunately we had to revert this PR because it had the side effect of forms without clickable submit buttons not being submittable anymore via Enter key. This is the case e.g. in AdminSystemConfiguration when using the search box and pressing Enter to show all matching results or in AdminCustomerUser searching for a user and pressing Enter.

If you have a solution for this side effect, we're happy to include it.

Thank you.

ZTrotter commented 5 months ago

@jepf @NiklasSchmitt

I have now created a solution to the above side-effect and would like to update the PR with the latest commit, but as the PR has been merged already, I'm not able to do so. Should I create a new PR for this fix or is there an alternative option?

jepf commented 5 months ago

@ZTrotter

👍 It would be best to create a new PR.

Thank you!

ZTrotter commented 5 months ago

Perfect, I'll do that.

Thanks!