@@ -410,8 +410,7 @@ abstract class AbstractControl<T> {
410410 return ;
411411 }
412412 _status = ControlStatus .valid;
413- updateValueAndValidity (updateParent: true , emitEvent: emitEvent);
414- _updateAncestors (updateParent);
413+ updateValueAndValidity (updateParent: updateParent, emitEvent: emitEvent);
415414 }
416415
417416 /// Disables the control.
@@ -1162,6 +1161,53 @@ abstract class FormControlCollection<T> extends AbstractControl<T> {
11621161
11631162 return result;
11641163 }
1164+
1165+ /// Enables the control.
1166+ ///
1167+ /// This means the control is included in validation checks and the aggregate
1168+ /// value of its parent. Its status recalculates based on its value and its
1169+ /// validators.
1170+ ///
1171+ /// When [updateParent] is false, mark only this control.
1172+ /// When true or not supplied (the default), marks all direct ancestors.
1173+ ///
1174+ /// When [emitEvent] is true or not supplied (the default), [valueChanges]
1175+ /// and [statusChanged] events are emitted if value or status change.
1176+ /// Otherwise the control update this values but none of this events are
1177+ /// emitted.
1178+ @override
1179+ void markAsEnabled ({bool updateParent = true , bool emitEvent = true }) {
1180+ forEachChild ((control) {
1181+ control.markAsEnabled (updateParent: false , emitEvent: emitEvent);
1182+ });
1183+
1184+ updateValueAndValidity (updateParent: updateParent, emitEvent: emitEvent);
1185+ }
1186+
1187+ /// Disables the control.
1188+ ///
1189+ /// This means the control is exempt from validation checks and excluded
1190+ /// from the aggregate value of any parent. Its status is `DISABLED` .
1191+ ///
1192+ /// If the control has children, all children are also disabled.
1193+ ///
1194+ /// When [updateParent] is false, mark only this control.
1195+ /// When true or not supplied (the default), marks all direct ancestors.
1196+ ///
1197+ /// When [emitEvent] is true or not supplied (the default), [valueChanges]
1198+ /// and [statusChanged] events are emitted if value or status change.
1199+ /// Otherwise the control update this values but none of this events are
1200+ /// emitted.
1201+ @override
1202+ void markAsDisabled ({bool updateParent = true , bool emitEvent = true }) {
1203+ forEachChild ((control) {
1204+ control.markAsDisabled (updateParent: false , emitEvent: emitEvent);
1205+ });
1206+
1207+ _errors.clear ();
1208+
1209+ updateValueAndValidity (updateParent: updateParent, emitEvent: emitEvent);
1210+ }
11651211}
11661212
11671213/// Tracks the value and validity state of a group of FormControl instances.
@@ -1350,49 +1396,6 @@ class FormGroup extends FormControlCollection<Map<String, Object?>> {
13501396 updateValue (value);
13511397 }
13521398
1353- /// Disables the control.
1354- ///
1355- /// This means the control is exempt from validation checks and excluded
1356- /// from the aggregate value of any parent. Its status is `DISABLED` .
1357- ///
1358- /// If the control has children, all children are also disabled.
1359- ///
1360- /// When [updateParent] is false, mark only this control.
1361- /// When true or not supplied (the default), marks all direct ancestors.
1362- ///
1363- /// When [emitEvent] is true or not supplied (the default), [valueChanges]
1364- /// and [statusChanged] events are emitted if value or status change.
1365- /// Otherwise the control update this values but none of this events are
1366- /// emitted.
1367- @override
1368- void markAsDisabled ({bool updateParent = true , bool emitEvent = true }) {
1369- _controls.forEach ((_, control) {
1370- control.markAsDisabled (updateParent: true , emitEvent: emitEvent);
1371- });
1372- super .markAsDisabled (updateParent: updateParent, emitEvent: emitEvent);
1373- }
1374-
1375- /// Enables the control.
1376- ///
1377- /// This means the control is included in validation checks and the aggregate
1378- /// value of its parent. Its status recalculates based on its value and its
1379- /// validators.
1380- ///
1381- /// When [updateParent] is false, mark only this control.
1382- /// When true or not supplied (the default), marks all direct ancestors.
1383- ///
1384- /// When [emitEvent] is true or not supplied (the default), [valueChanges]
1385- /// and [statusChanged] events are emitted if value or status change.
1386- /// Otherwise the control update this values but none of this events are
1387- /// emitted.
1388- @override
1389- void markAsEnabled ({bool updateParent = true , bool emitEvent = true }) {
1390- _controls.forEach ((_, control) {
1391- control.markAsEnabled (updateParent: true , emitEvent: emitEvent);
1392- });
1393- super .markAsEnabled (updateParent: updateParent, emitEvent: emitEvent);
1394- }
1395-
13961399 /// Appends all [controls] to the group.
13971400 void addAll (Map <String , AbstractControl <dynamic >> controls) {
13981401 _controls.addAll (controls);
@@ -1787,29 +1790,23 @@ class FormArray<T> extends FormControlCollection<List<T?>> {
17871790 /// and value when the control is reset. When false, no events are emitted.
17881791 @override
17891792 void markAsDisabled ({bool updateParent = true , bool emitEvent = true }) {
1793+ if (disabled) {
1794+ return ;
1795+ }
1796+
17901797 for (final control in _controls) {
1791- control.markAsDisabled (updateParent: true , emitEvent: emitEvent);
1798+ control.markAsDisabled (updateParent: false , emitEvent: emitEvent);
17921799 }
1793- super .markAsDisabled (updateParent: updateParent, emitEvent: emitEvent);
1794- }
17951800
1796- /// Enables the control. This means the control is included in validation
1797- /// checks and the aggregate value of its parent. Its status recalculates
1798- /// based on its value and its validators.
1799- ///
1800- /// When [updateParent] is true or not supplied (the default) each change
1801- /// affects this control and its parent, otherwise only affects to this
1802- /// control.
1803- ///
1804- /// When [emitEvent] is true or not supplied (the default), both the
1805- /// *statusChanges* and *valueChanges* emit events with the latest status
1806- /// and value when the control is reset. When false, no events are emitted.
1807- @override
1808- void markAsEnabled ({bool updateParent = true , bool emitEvent = true }) {
1809- forEachChild ((control) {
1810- control.markAsEnabled (updateParent: true , emitEvent: emitEvent);
1811- });
1812- super .markAsEnabled (updateParent: updateParent, emitEvent: emitEvent);
1801+ _status = ControlStatus .disabled;
1802+ _updateValue ();
1803+
1804+ if (emitEvent) {
1805+ _valueChanges.add (value);
1806+ _statusChanges.add (_status);
1807+ }
1808+
1809+ _updateAncestors (updateParent);
18131810 }
18141811
18151812 /// Insert a [control] at the given [index] position.
0 commit comments