-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
Form fields onChange callback should be called on reset #134295
Form fields onChange callback should be called on reset #134295
Conversation
90eea5c
to
ba88062
Compare
ba88062
to
2af641f
Compare
_effectiveController!.text = widget.initialValue!; | ||
}); | ||
} | ||
_cupertinoTextFormFieldRow.onChanged?.call(_effectiveController!.text); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we still call this if the value did not change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same for other FormField
s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I chose not to add such a check in order to be consistent with FormState.reset
which (indirectly) call the Form.onChanged
callback without checking if field values have changed.
I also checked that DropdownButton.onChanged
is called when the same entry is selected.
Maybe we should consider this is another issue/PR? I don't know if this was done on purpose.
@@ -272,6 +270,10 @@ class TextFormField extends FormField<String> { | |||
/// initialize its [TextEditingController.text] with [initialValue]. | |||
final TextEditingController? controller; | |||
|
|||
/// Called when the user initiates a change to the TextField's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be made a doc template and reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, I upated the PR accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution @bleroux. Just had a few comments.
2af641f
to
28efbee
Compare
28efbee
to
fc3af56
Compare
@@ -272,6 +270,12 @@ class TextFormField extends FormField<String> { | |||
/// initialize its [TextEditingController.text] with [initialValue]. | |||
final TextEditingController? controller; | |||
|
|||
/// {@template flutter.material.TestFormField.onChanged} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: TestFormField
-> TextFormField
. I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM w/ small nit. Thanks for fixing this @bleroux!
914a2fa
to
57c90cc
Compare
57c90cc
to
0ec68a8
Compare
## Description This PR fixes form fields in order to call the `onChange` callback when the form is reset. This change is based on the work done in flutter#123108. I considered adding the `onChange` callback to the `FormField` superclass but it would break existing code because two of the three subclasses defines the `onChange` callback with `ValueChanged<String>?` type and the third one defines it with `ValueChanged<String?>?`. ## Related Issue Fixes flutter#123009. ## Tests Adds 3 tests.
Description
This PR fixes form fields in order to call the
onChange
callback when the form is reset.This change is based on the work done in #123108.
I considered adding the
onChange
callback to theFormField
superclass but it would break existing code because two of the three subclasses defines theonChange
callback withValueChanged<String>?
type and the third one defines it withValueChanged<String?>?
.Related Issue
Fixes #123009.
Tests
Adds 3 tests.