Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
));
}

bool _autovalidate = false;
AutovalidateMode _autovalidateMode = AutovalidateMode.disabled;
bool _formWasEdited = false;

final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
Expand All @@ -104,7 +104,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
void _handleSubmitted() {
final FormState form = _formKey.currentState;
if (!form.validate()) {
_autovalidate = true; // Start validating on every change.
_autovalidateMode = AutovalidateMode.always; // Start validating on every change.
showInSnackBar('Please fix the errors in red before submitting.');
} else {
form.save();
Expand Down Expand Up @@ -180,7 +180,7 @@ class TextFormFieldDemoState extends State<TextFormFieldDemo> {
bottom: false,
child: Form(
key: _formKey,
autovalidate: _autovalidate,
autovalidateMode: _autovalidateMode,
onWillPop: _warnUserAboutInvalidData,
child: Scrollbar(
child: SingleChildScrollView(
Expand Down
5 changes: 5 additions & 0 deletions packages/flutter/lib/src/material/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,11 @@ class DropdownButtonFormField<T> extends FormField<T> {
InputDecoration decoration,
FormFieldSetter<T> onSaved,
FormFieldValidator<T> validator,
@Deprecated(
'Use autoValidateMode parameter which provide more specific '
'behaviour related to auto validation. '
'This feature was deprecated after v1.19.0.'
)
bool autovalidate = false,
AutovalidateMode autovalidateMode,
}) : assert(items == null || items.isEmpty || value == null ||
Expand Down
7 changes: 6 additions & 1 deletion packages/flutter/lib/src/material/text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export 'package:flutter/services.dart' show SmartQuotesType, SmartDashesType;
/// },
/// child: FocusTraversalGroup(
/// child: Form(
/// autovalidate: true,
/// autovalidateMode: AutovalidateMode.always,
/// onChanged: () {
/// Form.of(primaryFocus.context).save();
/// },
Expand Down Expand Up @@ -158,6 +158,11 @@ class TextFormField extends FormField<String> {
SmartDashesType smartDashesType,
SmartQuotesType smartQuotesType,
bool enableSuggestions = true,
@Deprecated(
'Use autoValidateMode parameter which provide more specific '
'behaviour related to auto validation. '
'This feature was deprecated after v1.19.0.'
)
bool autovalidate = false,
bool maxLengthEnforced = true,
int maxLines = 1,
Expand Down
29 changes: 14 additions & 15 deletions packages/flutter/lib/src/widgets/form.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ class Form extends StatefulWidget {
const Form({
Key key,
@required this.child,
this.autovalidate = false,
@Deprecated(
'Use autoValidateMode parameter which provide more specific '
'behaviour related to auto validation. '
'This feature was deprecated after v1.19.0.'
)
bool autovalidate = false,
this.onWillPop,
this.onChanged,
AutovalidateMode autovalidateMode,
Expand Down Expand Up @@ -114,11 +119,6 @@ class Form extends StatefulWidget {
/// {@macro flutter.widgets.child}
final Widget child;

/// If true, form fields will validate and update their error text
/// immediately after every change. Otherwise, you must call
/// [FormState.validate] to validate.
final bool autovalidate;

Choose a reason for hiding this comment

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

Turns out this is a breaking change. The public field is removed, not deprecated.

This affects (at least) flutter_form_builder.
flutter-form-builder-ecosystem/flutter_form_builder#465

Ideally, should (with appropriate deprecated tag) put something like

bool get autovalidate => autovalidateMode != AutovalidateMode.disabled;

Copy link
Contributor

Choose a reason for hiding this comment

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

@pedromassango oops did we miss this one?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm. Just checked form.dart file and I don't see any reference for final bool autovalidate. We did removed this intentionally in favour of AutovalidateMode property.

Maybe this is referencing a old commit file?!

Copy link
Member Author

Choose a reason for hiding this comment

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

bool get autovalidate => autovalidateMode != AutovalidateMode.disabled;

This is interesting and would prevent the breaking changes 🤔
@chunhtai do you think this we should put it back?

Copy link
Member Author

Choose a reason for hiding this comment

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

@skyeskie
What are the use cases of using this Widget's property?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should put this one back, but we should do

autovalidateMode = autovalidateMode ?? autovalidate ? AutovalidateMode.always : AutovalidateMode.disabled

Same as what we do for other formfield

Copy link
Member Author

Choose a reason for hiding this comment

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

Alright, I will send a PR to put it back ASAP

Choose a reason for hiding this comment

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

FormField has the exact same issue (below, 363-368)

@pedromassango
I personally don't use this, but just ran across when flutter_form_builder refused to compile, specifically when it tries to access autovalidate on FormField in its FormBuilderCustomField class here.

Copy link
Member Author

Choose a reason for hiding this comment

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

The PR is: #66267

@chunhtai I think we should add it back on formField widget too, right?


/// Enables the form to veto attempts by the user to dismiss the [ModalRoute]
/// that contains the form.
///
Expand Down Expand Up @@ -319,7 +319,12 @@ class FormField<T> extends StatefulWidget {
this.onSaved,
this.validator,
this.initialValue,
this.autovalidate = false,
@Deprecated(
'Use autoValidateMode parameter which provide more specific '
'behaviour related to auto validation. '
'This feature was deprecated after v1.19.0.'
)
bool autovalidate = false,
this.enabled = true,
AutovalidateMode autovalidateMode,
}) : assert(builder != null),
Expand Down Expand Up @@ -360,12 +365,6 @@ class FormField<T> extends StatefulWidget {
/// An optional value to initialize the form field to, or null otherwise.
final T initialValue;

/// If true, this form field will validate and update its error text
/// immediately after every change. Otherwise, you must call
/// [FormFieldState.validate] to validate. If part of a [Form] that
/// auto-validates, this value will be ignored.
final bool autovalidate;

/// Whether the form is able to receive user input.
///
/// Defaults to true. If [autovalidateMode] is not [AutovalidateMode.disabled],
Expand All @@ -382,8 +381,8 @@ class FormField<T> extends StatefulWidget {
/// will auto validate even without user interaction and
/// if [AutovalidateMode.disabled] the auto validation will be disabled.
///
/// Defaults to [AutovalidateMode.disabled] if [autovalidate] is false which
/// means no auto validation will occur. If [autovalidate] is true then this
/// Defaults to [AutovalidateMode.disabled] if `autovalidate` is false which
/// means no auto validation will occur. If `autovalidate` is true then this
/// is set to [AutovalidateMode.always] for backward compatibility.
/// {@endtemplate}
final AutovalidateMode autovalidateMode;
Expand Down