Repository navigation
[Form] AutovalidateMode.onUserInteraction validates Textfields without interaction #107350
Copy link
Copy link
Open
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsfound in release: 3.0Found to occur in 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1Found to occur in 3.1has partial patchThere is a PR awaiting someone to take it across the finish lineThere is a PR awaiting someone to take it across the finish linehas reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Description
Steps to Reproduce
Execute flutter run on the code sample
Expected results:
Screen.Recording.2022-07-09.at.9.42.26.PM.mov
Actual results:
Screen.Recording.2022-07-09.at.9.38.12.PM.mov
Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
final _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(20),
child: Column(
children: [
const Text('has issue onUserInteraction (wraped with Form)'),
Form(
key: _formKey,
autovalidateMode: AutovalidateMode.onUserInteraction,
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your Name',
),
validator: (val) {
return val!.length < 4 ? 'Not valid' : null;
},
),
const SizedBox(height: 20),
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email Id',
),
validator: (val) {
return val!.length < 4 ? 'email not valid' : null;
},
),
const SizedBox(height: 20),
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your password',
),
obscureText: true,
validator: (val) {
return val!.length < 4 ? 'password not valid' : null;
},
),
],
),
),
const SizedBox(height: 40),
const Text('Working fine onUserInteraction (wraped without Form)'),
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your Name',
),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (val) {
return val!.length < 4 ? 'Not valid' : null;
},
),
const SizedBox(height: 20),
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your email Id',
),
autovalidateMode: AutovalidateMode.onUserInteraction,
validator: (val) {
return val!.length < 4 ? 'email not valid' : null;
},
),
const SizedBox(height: 20),
TextFormField(
decoration: const InputDecoration(
hintText: 'Enter your password',
),
autovalidateMode: AutovalidateMode.onUserInteraction,
obscureText: true,
validator: (val) {
return val!.length < 4 ? 'password not valid' : null;
},
),
],
),
),
),
);
}
}
Logs
[✓] Flutter (Channel stable, 3.0.2, on macOS
12.4 21F79 darwin-arm, locale en-IN)
• Flutter version 3.0.2 at
/Users/newton/Development/flutter
• Upstream repository
https://github.com/flutter/flutter.git
• Framework revision cd41fdd495 (4 weeks
ago), 2022-06-08 09:52:13 -0700
• Engine revision f15f824b57
• Dart version 2.17.3
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android
devices (Android SDK version 32.0.0-rc1)
• Android SDK at
/Users/newton/Library/Android/sdk
• Platform android-32, build-tools
32.0.0-rc1
• Java binary at: /Applications/Android
Studio.app/Contents/jre/Contents/Home/bi
n/java
• Java version OpenJDK Runtime Environment
(build 11.0.12+0-b1504.28-7817840)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode
13.4.1)
• Xcode at
/Applications/Xcode.app/Contents/Develop
er
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google
Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.2)
• Android Studio at /Applications/Android
Studio.app/Contents
• Flutter plugin can be installed from:
🔨
https://plugins.jetbrains.com/plugin/921
2-flutter
• Dart plugin can be installed from:
🔨
https://plugins.jetbrains.com/plugin/635
1-dart
• Java version OpenJDK Runtime Environment
(build 11.0.12+0-b1504.28-7817840)
[✓] VS Code (version 1.68.1)
• VS Code at /Applications/Visual Studio
Code.app/Contents
• Flutter extension version 3.42.0
[✓] Connected device (3 available)
• sdk gphone64 arm64 (mobile) •
emulator-5554 • android-arm64 • Android
12 (API 31) (emulator)
• macOS (desktop) • macos
• darwin-arm64 • macOS 12.4 21F79
darwin-arm
• Chrome (web) • chrome
• web-javascript • Google Chrome
103.0.5060.53
[✓] HTTP Host Availability
• All required HTTP hosts are available
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3Issues that are less important to the Flutter projectIssues that are less important to the Flutter projecta: text inputEntering text in a text field or keyboard related problemsEntering text in a text field or keyboard related problemsfound in release: 3.0Found to occur in 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1Found to occur in 3.1has partial patchThere is a PR awaiting someone to take it across the finish lineThere is a PR awaiting someone to take it across the finish linehas reproducible stepsThe issue has been confirmed reproducible and is ready to work onThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesmaterial_ui package in flutter/packagespackageflutter/packages repository. See also p: labels.flutter/packages repository. See also p: labels.team-designOwned by Design Languages teamOwned by Design Languages teamtriaged-designTriaged by Design Languages teamTriaged by Design Languages team
Activity
Tonouewa-kefil commentedon Jul 10, 2022
So what is happening is, that you are auto validating the whole form instead of each Text form field.
code sample
newtaDev commentedon Jul 10, 2022
@Tonouewa-kefil
I'm asking why both ways behave differently? (
autovalidateMode: AutovalidateMode.onUserInteractionon Form widget and on eachTextFormField)Both should work the same right..?
Tonouewa-kefil commentedon Jul 11, 2022
@newtaDev
No, they won't work the same because, on one hand, you are auto validating the form which means any change that occurs in the form will trigger all the potential errors to appear, and on the other hand you are auto validating each TextForm Field which is what you most likely want to do.
maheshj01 commentedon Jul 11, 2022
Hi @newtaDev, Thanks for filing the issue. I am able to reproduce the issue, validation is run on all the fields even if they are not interacted. As per the docs
flutter doctor -v (mac)
[-]Weird behavior in `TextFormField` when `TextFormField` wrapped inside `Form` widget with `autovalidateMode` set to `AutovalidateMode.onUserInteraction`[/-][+][Form] `AutovalidateMode.onUserInteraction` validates all textfield without interaction[/+][-][Form] `AutovalidateMode.onUserInteraction` validates all textfield without interaction[/-][+][Form] `AutovalidateMode.onUserInteraction` validates all Textfields without interaction[/+]15 remaining items
flutter-triage-bot commentedon Jul 8, 2023
This issue is assigned but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!
pedromassango commentedon Jul 22, 2023
Removing my assignment for now
Hixie commentedon Aug 29, 2023
A partial patch for this PR exists in #120730.
Mairramer commentedon Jan 13, 2026
If PR #180822 gets merged, I will submit a follow-up fix, since my correction depends on it.