Skip to content

Respect per-field autovalidateMode priority#182752

Open
Mairramer wants to merge 8 commits intoflutter:masterfrom
Mairramer:feat/per-field-autovalidate-priority
Open

Respect per-field autovalidateMode priority#182752
Mairramer wants to merge 8 commits intoflutter:masterfrom
Mairramer:feat/per-field-autovalidate-priority

Conversation

@Mairramer
Copy link
Contributor

@Mairramer Mairramer commented Feb 23, 2026

Implemented a hierarchical validation logic: FormField.autovalidateMode now takes precedence over the parent Form settings. If the field-level mode is unspecified, it inherits the form-level configuration, with a final fallback to AutovalidateMode.disabled. Also fixes AutovalidateMode.onUserInteraction validates without user interaction.

Fixes #125766
Fixes #107350

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Feb 23, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors form validation logic to prioritize FormField.autovalidateMode over the parent Form's setting, which is a great enhancement for flexibility. The changes centralize validation logic within FormFieldState, leading to cleaner code. The tests have been updated appropriately to cover this new behavior. I have a couple of suggestions to improve documentation accuracy and code clarity.

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this approach, but we'll have to make sure the Google tests pass. I'm encouraged that the customer tests pass.

To be clear, this PR makes #180822 irrelevant right?

@Mairramer Mairramer requested a review from justinmc February 23, 2026 22:23
@Mairramer Mairramer requested a review from justinmc February 27, 2026 12:50
justinmc
justinmc previously approved these changes Mar 6, 2026
Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM to kick off the Google tests.

@justinmc
Copy link
Contributor

Welp it seems to have failed Google tests. I see a form field that used to be focused and showing a hint (min/max values) and a disabled button, but now the field is not focused and has no hint, and the button is enabled.

I believe the relevant FormField is a TextFormField with null passed to its autovalidateMode, and it is wrapped in a Form with no autovalidateMode passed. But with both the old and new code wouldn't it just end up using AutovalidateMode.disabled?

Or is there any other reason why this PR would cause that failure?

@Mairramer
Copy link
Contributor Author

Mairramer commented Mar 12, 2026

Welp it seems to have failed Google tests. I see a form field that used to be focused and showing a hint (min/max values) and a disabled button, but now the field is not focused and has no hint, and the button is enabled.

I believe the relevant FormField is a TextFormField with null passed to its autovalidateMode, and it is wrapped in a Form with no autovalidateMode passed. But with both the old and new code wouldn't it just end up using AutovalidateMode.disabled?

Or is there any other reason why this PR would cause that failure?

I tried to reproduce the scenario based on your description, but I couldn’t reproduce it locally. It’s possible I missed something, but I’m not sure what it might be.

Edit: It might be related to the fix for #107350.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

2 participants