-
Notifications
You must be signed in to change notification settings - Fork 167
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
Button click shortcut listener does not recognize value change when using control key #5959
Comments
Tested with Vaadin 14, RC1 in bower mode on a Windows server and Windows client with chrome.
|
I don't see this is a bug at all. What I've got from your description is: Is it correct ? Then it may not work as you have described since the currently focused field doesn't notify the Ctrl + Enter doesn't change the value. So all other values are changed except the value for currently You may not use value change mode I'm closing this issue as invalid. |
I disagree with that. From a Java developer point of view the shortcut listener calls click on the button, thus I expect the components to behave the same way, as if the user would manually move his mouse to the button and click it (especially when I use the method "clickInClient"). Not doing it this way, but telling the developer "for that you have to use EAGER on all your fields" is a bad DX in my view: Either you cannot use shortcuts or you have a flood of network requests for each character that is typed in - especially when the form is not only 3-4 simple textfields but consisting of text areas or other editor components, which will send their whole content to the server all the time. I could live with a scenario, where the normal button click + on change takes the current state from the server. But when having the special clickInClient I would expect at least, that this method behaves like user interaction (calling focus on the button and then click). |
I don't get your points. Do you understand what value change mode ON_CHANGE means ? Please explain me your understanding. In your scenario there is no value change. So the behavior is expected. Will you expect the required behavior If you set Well, I don't want to argue about this. I'm not going to fix this anyway. I think this is not a bug. |
Some simple use cases to show my issue: We have a form with a server side binder, read some values from the bean. The user changes now all fields (by using the keyboard and typing new characters in each field). Variants of the use case are:
Variant 1, usecase 1: Variant 1, usecase 2: Variant 2, usecase 1: Variant 2, usecase 2: Outcome I also agree, that the normal "click" method cannot check the client side, if there might be some unsent, but from the user's perspective changed value, that needs to be sent, but, the So, to sum up everything what the request for fix (or enhance) is: |
I agree with @stefanuebe, adding a click shortcut, I expect it to work the same as if I manually click the |
I can only agree with the messages from @Springrbua and @stefanuebe. The usability of the web page would be much better if an input value from the field could be transferred via shortcut even if the field still has the focus. As a workaround you can deselect the focus using client side code:
but since the Vaadin classes has |
@stefanuebe I have TimePicker, DateTimePicker and DatePicker in my form and they dont have change mode method. Any idea how to fix this in my case? |
It is sept 2021 and a Shortcut still cannot trigger value change regardless which I think this must be addressed. |
An update. If I do a
while the explicit |
@Avec112 Did you try with setting value change mode to TIMEOUT?
|
I had not but I have now. There is no difference. |
@hfazai With TIMEOUT it will probably only work, if you stop typing for long enough. |
I see but I will not try to circumvent this issue anymore. I see this as an clear bug unless Vaadin can convince me otherwise. I still think this is a Conclusion : Shortcuts cannot be used related to binding changed values. |
@hfazai With TIMEOUT it will probably only work, if you stop typing for long enough.
If the user uses the shortcut directly after he stops typing, the value on the server will probably be updated after the shortcut listener gets triggered
EAGER mode may work for you, but it makes more communication between client
and server.
Le mer. 22 sept. 2021 1:18 PM, Avec112 ***@***.***> a écrit :
… I see but I will not try to circumvent this issue anymore. I see this as
an clear bug unless Vaadin can convince me otherwise. I still think this is
a bug and not an issue which should be labeled enhancement. It can't be
so that a mouse click on a button the binder will fully populate the bean
based on any changes done while trigging the same button event with
button.click() it will not populate the changes.
- Conclusion* : Shortcuts cannot be used related to binding changed
values.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#5959 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ANS5JQIAE5A3MN6MSTHHMGDUDHCRPANCNFSM4H2OQQFQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Just encountered this issue. It's really not the behavior one would expect. The (maybe) naive expectation is that any user command (like clicking a button or triggering a shorcut) flushes all pending changes to inputs to the server beforehand. For button clicks it just seems to work as a happy accident because the input will lose its focus (and send its new value) before the button can be clicked. Judging from what I know, I'm not even sure this can be fixed transparently or generically, as it involves very component-specific behavior. I'd be happy with a workaround that simply imitates clicking an actual button, like I tried above. |
After some more experimentation, this is at least somewhat related to the following issue: vaadin/flow-components#530 TextField textField = new TextField();
Button button = new Button("Send");
Shortcuts.addShortcutListener(textField, event -> {
textField.blur();
button.clickInClient();
}, Key.ENTER).listenOn(textField);
button.addClickListener(event -> {
Notification.show(textField.getValue());
});
|
My current workaround is similar to the one posted by @Frettman but in my case, I don't have a
The drawback of this method is, that it needs another roundtrip, which is something I would like to prevent. |
This ticket/PR has been released with Vaadin 24.3.0.alpha1 and is also targeting the upcoming stable 24.3.0 version. |
Adds a note to point out how click notifier's `addClickShortcut` method's default behaviour has changed since 24.3. Related-to: vaadin/flow#5959
Adds a note to point out how click notifier's `addClickShortcut` method's default behaviour has changed since 24.3. Related-to: vaadin/flow#5959
* docs: update click shortcut chapter in shortcut article Adds a note to point out how click notifier's `addClickShortcut` method's default behaviour has changed since 24.3. Related-to: vaadin/flow#5959 * Update articles/create-ui/shortcut.asciidoc * First pass at editing. * Second pass at editing. --------- Co-authored-by: Russell JT Dyer <[email protected]> Co-authored-by: Mikhail Shabarov <[email protected]>
Adds setResetFocusOnActiveElement, resetFocusOnActiveElement and isResetFocusOnActiveElement to ShortcutRegistration class to optionally reset focus on active element (focused element in browser). Resetting means calling blur() and focus() on the active element to ensure that input fields with ValueChangeMode ON_CHANGE will fire value change event before shortcut handler is run. Updates ClickNotifier#addClickShortcut(Key,KeyModifier...) to reset focus on active element by default for click shortcuts. Fixes: #5959
* feat: reset focus on active element in ShortcutRegistration Adds setResetFocusOnActiveElement, resetFocusOnActiveElement and isResetFocusOnActiveElement to ShortcutRegistration class to optionally reset focus on active element (focused element in browser). Resetting means calling blur() and focus() on the active element to ensure that input fields with ValueChangeMode ON_CHANGE will fire value change event before shortcut handler is run. Updates ClickNotifier#addClickShortcut(Key,KeyModifier...) to reset focus on active element by default for click shortcuts. Fixes: #5959 * test: fixed tests * chore: added null checking and text changes * chore: added window.Vaadin.Flow.resetFocus function * fix: revert addClickShortcut to not reset focus by default Removes a call `setResetFocusOnActiveElement(true)` in `addClickShortcut` method in `ClickNotifier` to revert default behavior changes from #17826. Fixes: #18048 * chore: update Reset focus on active element to work in 23 Adjusted reset focus script snippet from Flow 24 to work with 23. * chore: formatting --------- Co-authored-by: Mikhail Shabarov <[email protected]>
Maybe it's a silly question, but couldn't or shouldn't this By the way, has this any practical use for focus shortcuts (since it's available in |
It used to be a default in the beginning, but then a couple of regressions bite us (e.g. this vaadin/flow-components#5733) and we reverted it to be opt-it, so not a default. |
Sounds like a good idea to me.
The patch was mainly for click shortcuts. I recall no direct usages for focus shortcuts. |
You can do it now with |
That issue just reads like a duplicate of this one. What were those regressions? If you don't completely trust this feature (yet), I'd like to know what I should be looking out for in terms of potential side effects :) |
Yes, usability is fine. My concern was finding this feature (and ideally being aware of it before you encounter the problem) in the first place. Mentioning this in |
There was regression with use case where click shortcut key like 'x' was also handled by TextField/Input to print out letter in an input field, leading to every second character following a press of the click shortcut key getting cleared. Ticket for more details: #18048 |
I see. Thanks for the information. So it seems rather safe to use in typical use cases (like ENTER to submit a form). |
Adds paragraph about `resetFocusOnActiveElement()` feature in `addClickShortcut` method. Related-to: #5959
Adds paragraph about `resetFocusOnActiveElement()` feature in `addClickShortcut` method. Related-to: #5959
This ticket/PR has been released with Vaadin 23.4.0.alpha1 and is also targeting the upcoming stable 23.4.0 version. |
Adds paragraph about `resetFocusOnActiveElement()` feature in `addClickShortcut` method. Related-to: #5959
Adds paragraph about `resetFocusOnActiveElement()` feature in `addClickShortcut` method. Related-to: #5959
Adds paragraph about `resetFocusOnActiveElement()` feature in `addClickShortcut` method. Related-to: #5959 Co-authored-by: Tomi Virtanen <[email protected]>
A simple use case: a form with some text fields, a rich text editor and a save button. The user changes stuff and wants to submit the form by using the ctrl + enter key.
The text fields are used as they are (value change mode ON_CHANGE), bound with a simple binder. To achieve the "on enter", we set a click shortcut with ENTER and CONTROL.
Now, when filling all fields and using the mouse to click the button, everything works fine.
When filling the fields and using the shortcut, the currently focused field does not get submitted.
Using a self defined shortcut listener and the button method clickInClient does not solve the problem
The problem seems to be the usage of the control key. When setting the short cut listener to ENTER only, it works finely (except for that the rich text editor focus needs to handle additional checkings)
Setting the value change mode to EAGER makes it work as a workaround.
The text was updated successfully, but these errors were encountered: