File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -151,6 +151,12 @@ class Formz {
151151 static bool validate (List <FormzInput <dynamic , dynamic >> inputs) {
152152 return inputs.every ((input) => input.isValid);
153153 }
154+
155+ /// Returns a [bool] given a list of [FormzInput] indicating whether
156+ /// all the inputs are pure.
157+ static bool isPure (List <FormzInput <dynamic , dynamic >> inputs) {
158+ return inputs.every ((input) => input.isPure);
159+ }
154160}
155161
156162/// Mixin that automatically handles validation of all [FormzInput] s present in
@@ -180,6 +186,12 @@ mixin FormzMixin {
180186 /// Whether the [FormzInput] values are not all valid.
181187 bool get isNotValid => ! isValid;
182188
189+ /// Whether all of the [FormzInput] are pure.
190+ bool get isPure => Formz .isPure (inputs);
191+
192+ /// Whether all of the [FormzInput] are dirty.
193+ bool get isDirty => ! isPure;
194+
183195 /// Returns all [FormzInput] instances.
184196 ///
185197 /// Override this and give it all [FormzInput] s in your class that should be
Original file line number Diff line number Diff line change @@ -26,6 +26,18 @@ void main() {
2626 expect (form.isValid, isTrue);
2727 expect (form.isNotValid, isFalse);
2828 });
29+
30+ test ('is pure when none of the inputs were touched' , () {
31+ final form = NameInputFormzMixin ();
32+ expect (form.isPure, isTrue);
33+ expect (form.isDirty, isFalse);
34+ });
35+
36+ test ('is dirty when one or multiple inputs were touched' , () {
37+ final form = NameInputFormzMixin (name: const NameInput .dirty ());
38+ expect (form.isDirty, isTrue);
39+ expect (form.isPure, isFalse);
40+ });
2941 });
3042
3143 group ('FormzInputErrorCacheMixin' , () {
You can’t perform that action at this time.
0 commit comments