@@ -398,7 +398,7 @@ void main() {
398398 expect (model.viewValue).toEqual ('animal' );
399399 }));
400400
401- it ('should set the form control to be untouched when the model is reset or submitted ' , inject ((TestBed _) {
401+ it ('should set the form control to be untouched when the model is reset' , inject ((TestBed _) {
402402 var form = _.compile ('<form name="duperForm">' +
403403 ' <input type="text" ng-model="myModel" probe="i" />' +
404404 '</form>' );
@@ -429,13 +429,36 @@ void main() {
429429 _.triggerEvent (input, 'blur' );
430430
431431 expect (formModel.touched).toBe (true );
432+ }));
433+
434+ it ('should reset each of the controls to be untouched only when the form has a valid submission' , inject ((Scope scope, TestBed _) {
435+ var form = _.compile ('<form name="duperForm">' +
436+ ' <input type="text" ng-model="myModel" probe="i" required />' +
437+ '</form>' );
438+
439+ NgForm formModel = _.rootScope.context['duperForm' ];
440+ var model = _.rootScope.context['i' ].directive (NgModel );
441+ var input = model.element;
442+ _.triggerEvent (input, 'blur' );
443+
444+ expect (formModel.touched).toBe (true );
445+ expect (model.touched).toBe (true );
446+ expect (formModel.invalid).toBe (true );
432447
433448 _.triggerEvent (form, 'submit' );
434449
450+ expect (formModel.touched).toBe (true );
451+ expect (model.touched).toBe (true );
452+ expect (formModel.invalid).toBe (true );
453+
454+ scope.apply (() {
455+ scope.context['myModel' ] = 'value' ;
456+ });
457+ _.triggerEvent (form, 'submit' );
458+
459+ expect (formModel.valid).toBe (true );
435460 expect (formModel.touched).toBe (false );
436- expect (formModel.untouched).toBe (true );
437- expect (form.classes.contains ('ng-touched' )).toBe (false );
438- expect (form.classes.contains ('ng-untouched' )).toBe (true );
461+ expect (model.touched).toBe (false );
439462 }));
440463 });
441464
0 commit comments