You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[web] onSubmitted of TextField invoked if another TextField is clicked #49785
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, v1.13.6, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.0)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.5)
[✓] IntelliJ IDEA Community Edition (version 2019.2)
[✓] Connected device (3 available)
@a-marenkov The current behavior was implemented this way on purpose. Can you explain why you'd like a different behavior? Is it preventing you from implementing something?
onSubmitted firing automatically makes sense to me as well and i would not have filed the issue, but:
It has different behavior on mobile - onSubmitted is not firing automatically if you tap another TextField.
It has different behavior on web if opened with mobile (tested on android in chrome app) - onSubmitted is not firing automatically if you tap another TextField.
Docs aren't clear about when onEditingComplete and onSubmitted are called. It says Called when the user submits editable content (e.g., user presses the "done" button on the keyboard) - but what are the other ways to "submit editable"?
@yjbanov Here are couple of cases in which this behavior is bad:
I have 2 TextFields. One for email, the other for password.
I want on enter pressed
in email move focus to password;
in password perform some request
(obviously, there would be also some kind of a login button on a screen to perform the request, but that's another story)
So i put this logic either onEditingComplete or onSubmitted
-> user enters email
-> preses enter and enters password
-> then decides to correct email (user mistyped email or wants to enter different email)
-> user clicks email TextField and here is the problem, it fires onSubmitted and thus the request
I have 3 TextFields.
I want on enter pressed move focus to next TextField, so i put this logic either onEditingComplete or onSubmitted.
-> user enters text in first TextField
-> preses enter and enters text in second TextField
-> then decides to correct text in first TextField
-> user clicks on first TextField and here is the problem - for half a second the third TextField gets focused and then first TextField gets focused (it looks buggy for user)
Maybe, there's another way to implement cases above that i don't know.
On mobile i don't face this problems with this implementation.
P.S. I'm sorry, i think this issue should not really be about onSubmitted alone, but also about onEditingComplete (since it seems it's more appropriate to use for focus logic).
Reacted by Richard Johnson, Polina Cherkasova, Dominik Roszkowski, Nikolai, Niranjan G Mandan and Gyuri Majercsik
Update In the second case above to reproduce the bug it might take more than one click on another TextField. Try switching between TextFields back and forth (requires at least 3 TextFields).
I have at least 2 TextFields in a ListView (somewhere at the end of it).
I want on enter pressed move focus to next TextField, so i put this logic either onEditingComplete or onSubmitted.
-> user scrolls downwards and enters text in first TextField
-> then decides to scoll upwards by dragging
-> drags the ListView, and here is the problem - ListView would scroll upwards by dragging and also would autoscroll downwards to second TextField (because it gets focused as user taps blanc space).
It looks buggy.
@jlubeck I understand the confusion. You are right the documentation is not descriptive and leads to confusion. We should also have the behavior described per platform if there is a difference between them.
I'll discuss this with other member worked on text editing this week and update this issue (and the documentations).
Reacted by Jan Lübeck, Alexander Marenkov and Javi Hurtado
@nturgut It is fine that now the textfield will not submit its content when click on other parts of the page. But shouldn't the text-field lose focus just like any other standard web text-field? The change in this PR caused a regression in my opinion as now the text field will not lose focus when clicking away.
Reacted by Javi Hurtado, Nicolas Dion-Bouchard, Nikolai and Fabrice TEICHTEIL-KOENIGSBUCH
Maybe it's a noob question but: where can I find in which version of Flutter will this update be found? I know it's been merged but I have a hard time finding when it's available in Flutter :) Thanks!
Sorry for the late reply. I checked with developers who frequently worked on text editing.
The current API:
(1) Both onEditingComplete and onSubmitted are called at the same time.
(2) onSubmitted (which has the value) is indicates user the text editing is complete.
(3) onEditingComplete is for overriding the default behavior of focus changes.
As also suggested by @kunit1: If TextFields do not lose focus when other areas are clicked (mouse click or touch) by the user so web scenarios will be hard to implement. We need either the existing onEditingComplete callback to act differently than the onSubmit callback, and notify these blur event. Or we need to add a new callback to support development.
I am working on a document discussing these options. I'll add a link here.
That's good to hear. Though the onSubmited beeing called when we click outside the editing field is kinda strange. We should at least receive a value saying what caused the "submission". In my opinion, changing focus out of the field is not a mark of submission but I understand someone might see it differently. For me, hitting the "enter" or "send" button would be submission, nothing else. In any case, if we can receive the cause of the said submission, that would be fine so just adding an argument to the handler would work for me.
[✓] Flutter (Channel master, 1.22.0-10.0.pre.269, on Mac OS X 10.15.6 19G2021 x86_64, locale en)
• Flutter version 1.22.0-10.0.pre.269 at /Users/pedromassango/dev/SDKs/flutter_master
• Framework revision 51fa704642 (2 days ago), 2020-09-19 11:27:04 -0700
• Engine revision 4b8477d115
• Dart version 2.10.0 (build 2.10.0-142.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.1)
• Android SDK at /Users/pedromassango/Library/Android/sdk
• Platform android-30, build-tools 30.0.1
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.0)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.0, Build version 12A7209
• CocoaPods version 1.9.3
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[!] Android Studio (version 4.0)
• Android Studio at /Applications/Android Studio.app/Contents
✗ Flutter plugin not installed; this adds Flutter specific functionality.
✗ Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6222593)
[✓] IntelliJ IDEA Community Edition (version 2020.2.2)
• IntelliJ at /Applications/IntelliJ IDEA CE.app
• Flutter plugin version 49.0.4
• Dart plugin version 202.7319.5
[✓] VS Code (version 1.48.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.14.1
[✓] Connected device (4 available)
• sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)
• macOS (desktop) • macos • darwin-x64 • Mac OS X 10.15.6 19G2021 x86_64
• Web Server (web) • web-server • web-javascript • Flutter Tools
• Chrome (web) • chrome • web-javascript • Google Chrome 85.0.4183.102
! Doctor found issues in 1 category.
Process finished with exit code 0
Closing this as probably fixed. Could everyone who still has this problem please file a new issue with the exact description of what happens, logs, and the output of flutter doctor -v.
All system setups can be slightly different, so it's always better to open new issues and reference related issues.
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.
Activity
yjbanov commentedon Jan 30, 2020
@a-marenkov The current behavior was implemented this way on purpose. Can you explain why you'd like a different behavior? Is it preventing you from implementing something?
/cc @nturgut
kunit1 commentedon Jan 31, 2020
I tested the supplied sample code and this is what I observed on master:
a. text-field is now focused (good)
a. text-field is now unfocused (good)
b. onSubmitted fires automatically (?)
I think the onSubmitted firing automatically makes sense to me.
a-marenkov commentedon Jan 31, 2020
@yjbanov @kunit1
onSubmittedfiring automatically makes sense to me as well and i would not have filed the issue, but:onSubmittedis not firing automatically if you tap anotherTextField.onSubmittedis not firing automatically if you tap anotherTextField.onEditingCompleteandonSubmittedare called. It saysCalled when the user submits editable content (e.g., user presses the "done" button on the keyboard)- but what are the other ways to "submit editable"?@yjbanov Here are couple of cases in which this behavior is bad:
I want on enter pressed
(obviously, there would be also some kind of a login button on a screen to perform the request, but that's another story)
So i put this logic either
onEditingCompleteoronSubmitted-> user enters email
-> preses enter and enters password
-> then decides to correct email (user mistyped email or wants to enter different email)
-> user clicks email TextField and here is the problem, it fires
onSubmittedand thus the requestI want on enter pressed move focus to next TextField, so i put this logic either
onEditingCompleteoronSubmitted.-> user enters text in first TextField
-> preses enter and enters text in second TextField
-> then decides to correct text in first TextField
-> user clicks on first TextField and here is the problem - for half a second the third TextField gets focused and then first TextField gets focused (it looks buggy for user)
Maybe, there's another way to implement cases above that i don't know.
On mobile i don't face this problems with this implementation.
P.S. I'm sorry, i think this issue should not really be about onSubmitted alone, but also about onEditingComplete (since it seems it's more appropriate to use for focus logic).
a-marenkov commentedon Jan 31, 2020
Update In the second case above to reproduce the bug it might take more than one click on another TextField. Try switching between TextFields back and forth (requires at least 3 TextFields).
a-marenkov commentedon Feb 3, 2020
@yjbanov Another case would be:
I have at least 2 TextFields in a ListView (somewhere at the end of it).
I want on enter pressed move focus to next TextField, so i put this logic either onEditingComplete or onSubmitted.
-> user scrolls downwards and enters text in first TextField
-> then decides to scoll upwards by dragging
-> drags the ListView, and here is the problem - ListView would scroll upwards by dragging and also would autoscroll downwards to second TextField (because it gets focused as user taps blanc space).
It looks buggy.
20 remaining items
nturgut commentedon Jun 4, 2020
@jlubeck I understand the confusion. You are right the documentation is not descriptive and leads to confusion. We should also have the behavior described per platform if there is a difference between them.
I'll discuss this with other member worked on text editing this week and update this issue (and the documentations).
kunit1 commentedon Jun 8, 2020
@nturgut It is fine that now the textfield will not submit its content when click on other parts of the page. But shouldn't the text-field lose focus just like any other standard web text-field? The change in this PR caused a regression in my opinion as now the text field will not lose focus when clicking away.
NicolasDionB commentedon Jun 15, 2020
Maybe it's a noob question but: where can I find in which version of Flutter will this update be found? I know it's been merged but I have a hard time finding when it's available in Flutter :) Thanks!
nturgut commentedon Jun 26, 2020
Sorry for the late reply. I checked with developers who frequently worked on text editing.
The current API:
(1) Both onEditingComplete and onSubmitted are called at the same time.
(2) onSubmitted (which has the value) is indicates user the text editing is complete.
(3) onEditingComplete is for overriding the default behavior of focus changes.
PR(flutter-team-archive/engine#18743) is added to put web in sync with the current API documentation.
As also suggested by @kunit1: If TextFields do not lose focus when other areas are clicked (mouse click or touch) by the user so web scenarios will be hard to implement. We need either the existing onEditingComplete callback to act differently than the onSubmit callback, and notify these blur event. Or we need to add a new callback to support development.
I am working on a document discussing these options. I'll add a link here.
NicolasDionB commentedon Jun 28, 2020
That's good to hear. Though the onSubmited beeing called when we click outside the editing field is kinda strange. We should at least receive a value saying what caused the "submission". In my opinion, changing focus out of the field is not a mark of submission but I understand someone might see it differently. For me, hitting the "enter" or "send" button would be submission, nothing else. In any case, if we can receive the cause of the said submission, that would be fine so just adding an argument to the handler would work for me.
ironpotter commentedon Jul 15, 2020
Found some workaround, that emulates onSubmit action and losing focus doesn't trigger onSubmit.
sayurikunugi commentedon Jul 16, 2020
@ironpotter
Thank you, your solution works for me!
Just 1 thing, if the user inputs enter in the middle of text, it's not working right, so, I changed
to
ironpotter commentedon Jul 19, 2020
@sayurikunugi Thank you. You're right.
pedromassangocode commentedon Sep 21, 2020
Hi @a-marenkov
I cannot reproduce this on latest
masterchannel.sample code
flutter doctor -v
Closing this as probably fixed. Could everyone who still has this problem please file a new issue with the exact description of what happens, logs, and the output of
flutter doctor -v.All system setups can be slightly different, so it's always better to open new issues and reference related issues.
github-actions commentedon Aug 12, 2021
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -vand a minimal reproduction of the issue.