Skip to content

Commit 9814303

Browse files
matskomhevery
authored andcommitted
fix(NgModelValidators): ensure all validators can properly toggle attribute values
1 parent 0622f3a commit 9814303

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

lib/directive/ng_model_validators.dart

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ class NgModelMaxNumberValidator implements NgValidator {
132132
try {
133133
num parsedValue = double.parse(value);
134134
_max = parsedValue.isNaN ? _max : parsedValue;
135+
} catch(e) {
136+
_max = null;
137+
} finally {
135138
_ngModel.validateLater();
136-
} catch(e) {};
139+
}
137140
}
138141

139142
bool isValid(modelValue) {
@@ -180,8 +183,11 @@ class NgModelMinNumberValidator implements NgValidator {
180183
try {
181184
num parsedValue = double.parse(value);
182185
_min = parsedValue.isNaN ? _min : parsedValue;
186+
} catch(e) {
187+
_min = null;
188+
} finally {
183189
_ngModel.validateLater();
184-
} catch(e) {};
190+
}
185191
}
186192

187193
bool isValid(modelValue) {

test/directive/ng_model_validators_spec.dart

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,38 @@ void main() {
595595

596596
expect(model.valid).toBe(true);
597597
});
598+
599+
it('ng-min', () {
600+
var input = build('ng-min', 'number');
601+
scope.apply(() {
602+
scope.context['attr'] = '5.0';
603+
scope.context['value'] = 3;
604+
});
605+
606+
expect(model.valid).toBe(false);
607+
608+
scope.apply(() {
609+
scope.context['attr'] = null;
610+
});
611+
612+
expect(model.valid).toBe(true);
613+
});
614+
615+
it('ng-max', () {
616+
var input = build('ng-max', 'number');
617+
scope.apply(() {
618+
scope.context['attr'] = '5.0';
619+
scope.context['value'] = 8;
620+
});
621+
622+
expect(model.valid).toBe(false);
623+
624+
scope.apply(() {
625+
scope.context['attr'] = null;
626+
});
627+
628+
expect(model.valid).toBe(true);
629+
});
598630
});
599631
});
600632
}

0 commit comments

Comments
 (0)