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

[General]: Validation focuses latest invalid field instead of first #1392

Open
3 of 7 tasks
uragecz opened this issue May 16, 2024 · 0 comments
Open
3 of 7 tasks

[General]: Validation focuses latest invalid field instead of first #1392

uragecz opened this issue May 16, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@uragecz
Copy link

uragecz commented May 16, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Package/Plugin version

9.2.1

Platforms

  • Android
  • iOS
  • Linux
  • MacOS
  • Web
  • Windows

Flutter doctor

Flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.16.8, on macOS 14.4.1 23E224 darwin-arm64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.3)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.89.1)
[✓] Connected device (4 available)            
[✓] Network resources

• No issues found!

Minimal code example

Code sample
  final _formKey = GlobalKey<FormState>();
  
   Widget build(BuildContext context) {
   return(Column(children: [
Form(key: _formKey, child: Column(children: [
      FormBuilderTextField(
        name: 'firstname',
        autovalidateMode: AutovalidateMode.onUserInteraction,
        initialValue: '',
        onChanged: (text) {},
        validator: (value) {
            return 'Required';
        },
      ),
       SizedBox(height: 30, width: 30),
      FormBuilderTextField(
        name: "lastname",
        autovalidateMode: AutovalidateMode.onUserInteraction,
        initialValue: '',
        onChanged: (text) {},
        validator: (value) {
            return 'Required';
        },
      ),
       SizedBox(height: 30, width: 30),
      FormBuilderDateTimePicker(
        name: "date_of_birthday",
        autovalidateMode: AutovalidateMode.onUserInteraction,
        inputType: InputType.date
        initialDate: DateTime(DateTime.now().year - 30, 1, 1),
        onChanged: (text) {},
        validator: (value) {
            return 'Required';
        },
      )
 ]), 
 TextButton(onPressed: () {_formKey.currentState?.validate() },child: Text('Submit'))
 ]));

Current Behavior

I have form with many FormBuilderTextFields, and some of them are required - (they have validator that checks if its value empty or not), when i am trying to submit the form, calling validation - _formKey.currentState?.validate(), the latest invalid FormField is being focused instead of first one. In my case the latest is FormBuilderDateTimePicker, so when i pres "Submit", the date picker is being opened.

Expected Behavior

After validation, the first invalid Field in the tree should be focused.

Steps To Reproduce

Aditional information

I suppose this is not desired behaviour, but if from some unknown reason that i haven't found this is wanted. Is there at least some way to prevent date picker from opening its picker / dialog ?

I also think that this issue is related to this - #1253, where the focused were jumped to the latest input despite there were also another invalid input above
No response

@uragecz uragecz added the bug Something isn't working label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant