This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Expand file tree Collapse file tree 3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ abstract class NgControl implements NgDetachAware {
49
49
untouched = true ;
50
50
}
51
51
52
+ bool hasError (String key) => errors.containsKey (key);
53
+
52
54
_onSubmit (bool valid) {
53
55
if (valid) {
54
56
_submit_valid = true ;
@@ -241,5 +243,6 @@ class NgNullControl implements NgControl {
241
243
242
244
reset () => null ;
243
245
detach () => null ;
246
+ bool hasError (String key) => false ;
244
247
245
248
}
Original file line number Diff line number Diff line change @@ -342,6 +342,32 @@ void main() {
342
342
}));
343
343
});
344
344
345
+ describe ('error handling' , () {
346
+ it ('should return true or false depending on if an error exists on a form' ,
347
+ inject ((Scope scope, TestBed _) {
348
+
349
+ var element = $('<form name="myForm">'
350
+ ' <input type="text" ng-model="input" name="input" />' +
351
+ '</form>' );
352
+
353
+ _.compile (element);
354
+ scope.apply ();
355
+
356
+ var form = scope.context['myForm' ];
357
+ NgModel input = form['input' ];
358
+
359
+ expect (form.hasError ('big-failure' )).toBe (false );
360
+
361
+ form.updateControlValidity (input, "big-failure" , false );
362
+
363
+ expect (form.hasError ('big-failure' )).toBe (true );
364
+
365
+ form.updateControlValidity (input, "big-failure" , true );
366
+
367
+ expect (form.hasError ('big-failure' )).toBe (false );
368
+ }));
369
+ });
370
+
345
371
describe ('reset()' , () {
346
372
it ('should reset the model value to its original state' , inject ((TestBed _) {
347
373
_.compile ('<form name="superForm">' +
Original file line number Diff line number Diff line change @@ -981,6 +981,30 @@ void main() {
981
981
}));
982
982
});
983
983
984
+ describe ('error handling' , () {
985
+ it ('should return true or false depending on if an error exists on a form' ,
986
+ inject ((Scope scope, TestBed _) {
987
+
988
+ var element = $('<input type="text" ng-model="input" name="input" probe="i" />' );
989
+
990
+ _.compile (element);
991
+ scope.apply ();
992
+
993
+ Probe p = scope.context['i' ];
994
+ NgModel model = p.directive (NgModel );
995
+
996
+ expect (model.hasError ('big-failure' )).toBe (false );
997
+
998
+ model.setValidity ("big-failure" , false );
999
+
1000
+ expect (model.hasError ('big-failure' )).toBe (true );
1001
+
1002
+ model.setValidity ("big-failure" , true );
1003
+
1004
+ expect (model.hasError ('big-failure' )).toBe (false );
1005
+ }));
1006
+ });
1007
+
984
1008
describe ('text-like events' , () {
985
1009
it ('should update the binding on the "input" event' , inject (() {
986
1010
_.compile ('<input type="text" ng-model="model" probe="p">' );
You can’t perform that action at this time.
0 commit comments