Skip to content

Commit 19f25b9

Browse files
committed
feat(models): Add auto-validation to clearValidators
#491 This adds optional parameters to the `clearValidators` method to support automatic validation after clearing validators. - The `clearValidators` signature is updated to include `autoValidate`, `updateParent`, and `emitEvent` boolean parameters. - If `autoValidate` is set to `true`, `updateValueAndValidity()` is called immediately, allowing the control's validity to be recalculated with the specified options for parent updates and event emissions.
1 parent 9a484a9 commit 19f25b9

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 18.2.1
2+
3+
## Enhances
4+
5+
- Added optional parameters to the `clearValidators` method to support automatic validation after
6+
clearing validators.
7+
18
# 18.2.0
29

310
## Features

lib/src/models/models.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,16 @@ abstract class AbstractControl<T> {
142142
}
143143

144144
/// Empties out the sync validator list.
145-
///
146-
/// When you add or remove a validator at run time, you must call
147-
/// **updateValueAndValidity()**, or assign a new value to the control for
148-
/// the new validation to take effect.
149-
void clearValidators() {
145+
void clearValidators({
146+
bool autoValidate = false,
147+
bool updateParent = true,
148+
bool emitEvent = true,
149+
}) {
150150
_validators.clear();
151+
152+
if (autoValidate) {
153+
updateValueAndValidity(updateParent: updateParent, emitEvent: emitEvent);
154+
}
151155
}
152156

153157
/// The list of async functions that determines the validity of this control.

0 commit comments

Comments
 (0)