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

[Form Inputs]: Enter Triggers Submit Instantly & Should be Opt-In #10534

Open
1 task done
texttechne opened this issue Jan 13, 2025 · 3 comments · May be fixed by #10613
Open
1 task done

[Form Inputs]: Enter Triggers Submit Instantly & Should be Opt-In #10534

texttechne opened this issue Jan 13, 2025 · 3 comments · May be fixed by #10613
Assignees
Labels
bug This issue is a bug in the code High Prio TOPIC RL

Comments

@texttechne
Copy link

texttechne commented Jan 13, 2025

Bug Description

Affected Version: v2 (didn't occur in v1)
Affected Components: Let's take the ui5-input as example, but it applies to all other form components as well
Used Framework: React & UI5-WCR

Bug 1: Submit Event Triggered Too Soon

When the user presses Enter, the submit event is triggered immediately. However, other events aren't triggered beforehand, most prominently the change event isn't triggered before the submit event.

Just to be clear: It works when you click the submit button manually, because you leave the field by clicking the button and thereby trigger the change event. So this bug really only occurs when "Enter" is pressed via keyboard or send via mobile scanner device when stuff is scanned.

This is required, however, to implement any form validation solution. Using the change event was a workable and general way for us to hook our validation solution into UI5-WC, which doesn't work anymore. This bug makes it hard to use any validation framework; we are using react-hook-form, for example.

Our workaround attempts are based to turn off that submit behavior.

Bug 2: The Enter-Behavior Should Be Opt-In

While it's kind of best practice to use Enter as form submit, this doesn't hold true for all use cases.
We, for example, often want to use Enter as way to focus the next input field instead of submitting the whole form.

Example: Mobile scanner device: you scan a QR code value into one field and the device also adds an emulated Enter. Because you might need to scan multiple things (eg. product and batch) we want to focus the next field, so that the workflow of the employee won't get interrupted.

Hence, it would be cool to consciously opt-in to the submit behavior.

Affected Component

All Form Inputs

Expected Behaviour

  1. Change and other events are triggered before submit
  2. Behavior of Enter within input fields needs to be customizable (or at least opt-in to submit behavior)

Isolated Example

https://stackblitz.com/edit/js-ozhtujoe?file=index.js

Steps to Reproduce

  1. Open "Console" in example
  2. Enter some value into the standard input and press "Enter"
  3. See the logged results: 1. change event, 2. submit event
  4. Same procedure with the UI5-Input
  5. Result: Reversed order

Log Output, Stack Trace or Screenshots

No response

Priority

High

UI5 Web Components Version

2.6.2, but probably 2.x

Browser

Chrome, Firefox, Safari, Edge

Operating System

Windows

Additional Context

No response

Organization

No response

Declaration

  • I’m not disclosing any internal or sensitive information.
@texttechne texttechne added the bug This issue is a bug in the code label Jan 13, 2025
@IlianaB
Copy link
Member

IlianaB commented Jan 13, 2025

Hello @SAP/ui5-webcomponents-topic-rl , please have a look at this issue.
When ui5-input is placed in form, upon pressing Enter "submit" event is fired before the "change" event of ui5-input, while with native input the order of events is reversed.

@MapTo0 MapTo0 moved this from New Issues to In progress in Maintenance - Topic RL Jan 21, 2025
@MapTo0 MapTo0 self-assigned this Jan 21, 2025
MapTo0 added a commit that referenced this issue Jan 21, 2025
@MapTo0 MapTo0 linked a pull request Jan 21, 2025 that will close this issue
@MapTo0
Copy link
Member

MapTo0 commented Jan 22, 2025

Hey @texttechne

Thanks for the remarks!
I've considered it to be onkeyup but holding enter keeps on firing submit event on the native input.
Thats why we decided to keep it on the keydown.

Best Regards,
Martin

@texttechne
Copy link
Author

Hi @MapTo0,

thanks for the quick feedback!

You're talking about implementation details, however the requirements for and consequences of any implementation are essential.
And here I would like to ask: Would you agree that the requirements / problems I've named are relevant?

  • change must be triggered before submit (actually the complete event chain must be respected)
  • we need a way to prevent the form submit

If so, then you should solve these issues or, if you can't (worst case scenario), drop the feature altogether.

If this feature had been implemented as opt-in instead of being the default behavior from the get go, it wouldn't be a breaking change. Also, while this behavior is in line with standard HTML forms (not completely, you need to a add a form tag at least), SAPUI5 behaves differently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug in the code High Prio TOPIC RL
Projects
Status: In progress
Development

Successfully merging a pull request may close this issue.

3 participants