Skip to content

Commit

Permalink
Merge branch 'release/16.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
joanpablo committed Aug 21, 2023
2 parents b0f5c41 + f4c51c0 commit 12f2172
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 8 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/reactive_forms.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
# This job runs on Linux
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: subosito/flutter-action@v1
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.10.0"
channel: "stable"
Expand All @@ -33,8 +33,8 @@ jobs:
name: Analyze
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: subosito/flutter-action@v1
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.10.0"
channel: "stable"
Expand All @@ -48,8 +48,8 @@ jobs:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: subosito/flutter-action@v1
- uses: actions/checkout@v3
- uses: subosito/flutter-action@v2
with:
flutter-version: "3.10.0"
channel: "stable"
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 16.1.0

## Features

- Add `markAsPending()` method to `AbstractControl` to allow set the status
to PENDING by demand.

# 16.0.4

## Fixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ dependencies:
flutter:
sdk: flutter

reactive_forms: ^16.0.4
reactive_forms: ^16.1.0
```
Then run the command `flutter packages get` on the console.
Expand Down
24 changes: 24 additions & 0 deletions lib/src/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ abstract class AbstractControl<T> {
/// * VALID: This control has passed all validation checks.
/// * INVALID: This control has failed at least one validation check.
/// * PENDING: This control is in the midst of conducting a validation check.
/// * DISABLED: This control is exempt from ancestor calculations of
/// validity or value.
///
/// These status values are mutually exclusive, so a control cannot be both
/// valid AND invalid or invalid AND pending.
Expand Down Expand Up @@ -420,6 +422,28 @@ abstract class AbstractControl<T> {
_updateAncestors(updateParent);
}

/// Marks the control as `pending`.
///
/// A control is pending while the control performs async validation.
///
/// When [updateParent] is false, mark only this control. When true or not
/// supplied, marks all direct ancestors. Default is true.
///
/// When [emitEvent] is true or not supplied (the default), a [statusChanged]
/// event is emitted.
///
void markAsPending({bool updateParent = true, bool emitEvent = true}) {
_status = ControlStatus.pending;

if (emitEvent) {
this._statusChanges.add(_status);
}

if (updateParent) {
parent?.markAsPending(updateParent: updateParent, emitEvent: emitEvent);
}
}

/// Disposes the control
void dispose() {
_statusChanges.close();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: reactive_forms
description: This is a model-driven approach to handling form inputs and validations, heavily inspired in Angular Reactive Forms.
version: 16.0.4
version: 16.1.0
homepage: "https://github.com/joanpablo/reactive_forms"

environment:
Expand Down
19 changes: 19 additions & 0 deletions test/src/models/form_array_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,25 @@ void main() {
// Then: array value is patched
expect(array.value, [2, 2], reason: 'array value not patched');
});

test(
'Test that markAsPending() a control, set pending status to the array '
'as well.', () {
// Given: an array with valid status.
final array = FormArray<int>([
FormControl<int>(value: 1),
]);

// Expect: the array to be VALID and not PENDING.
expect(array.valid, true);
expect(array.pending, false);

// When: I call mark a child control as PENDING.
array.controls.first.markAsPending();

// Then: the status of the array is PENDING as well.
expect(array.pending, true);
});
});
}

Expand Down
15 changes: 15 additions & 0 deletions test/src/models/form_control_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,20 @@ void main() {
// Then: a new async validator is added
expect(formControl.asyncValidators.length, 1);
});

test('Test that markAsPending() change the status to PENDING.', () {
// Given: a control with valid status.
final control = FormControl<String>(value: 'Reactive Forms');

// Expect: the control to be VALID and not PENDING.
expect(control.valid, true);
expect(control.pending, false);

// When: I call markAsPending() method.
control.markAsPending();

// Then: the status is PENDING.
expect(control.pending, true);
});
});
}
18 changes: 18 additions & 0 deletions test/src/models/form_group_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -982,5 +982,23 @@ void main() {
// Expect: an assertion error
expect(form, throwsAssertionError);
});

test(
'Test that markAsPending() a control, set pending status to the group '
'as well.', () {
// Given: a form group with valid status.
final form =
FormGroup({'name': FormControl<String>(value: "Reactive Forms")});

// Expect: the group to be VALID and not PENDING.
expect(form.valid, true);
expect(form.pending, false);

// When: I call mark a child control as PENDING.
form.control('name').markAsPending();

// Then: the status of the Form Group is PENDING as well.
expect(form.pending, true);
});
});
}

0 comments on commit 12f2172

Please sign in to comment.