This repository was archived by the owner on Feb 22, 2018. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -74,8 +74,8 @@ class NgModel extends NgControl implements AttachAware {
74
74
*/
75
75
void reset () {
76
76
markAsUntouched ();
77
- _processViewValue (_originalValue);
78
77
modelValue = _originalValue;
78
+ _processViewValue (_originalValue);
79
79
}
80
80
81
81
void onSubmit (bool valid) {
Original file line number Diff line number Diff line change @@ -1380,6 +1380,39 @@ void main() {
1380
1380
expect (model.modelValue).toEqual ('animal' );
1381
1381
expect (model.viewValue).toEqual ('animal' );
1382
1382
});
1383
+
1384
+ it ('should revalidate itself after the form is reset ' , (Scope scope) {
1385
+ _.compile ('<form name="myForm" novalidate>' +
1386
+ ' <input type="text" ng-required="true" ng-model="inputValue" probe="i">' +
1387
+ '</form>' );
1388
+
1389
+ scope.apply ();
1390
+
1391
+ var form = _.rootScope.context['myForm' ];
1392
+ var formElement = form.element.node;
1393
+
1394
+ var input = _.rootScope.context['i' ].directive (NgModel );
1395
+ var inputElement = input.element.node;
1396
+
1397
+ expect (form.valid).toBe (false );
1398
+ expect (form.invalid).toBe (true );
1399
+
1400
+ inputElement.value = 'a special value' ;
1401
+ _.triggerEvent (inputElement, 'input' );
1402
+ scope.apply ();
1403
+
1404
+ expect (form.valid).toBe (true );
1405
+ expect (form.invalid).toBe (false );
1406
+
1407
+ form.reset ();
1408
+ //we need to run apply to properly update the input dom element
1409
+ scope.apply ();
1410
+
1411
+ expect (scope.context['inputValue' ]).toBe (null );
1412
+ expect (inputElement.value.length).toBe (0 );
1413
+ expect (form.valid).toBe (false );
1414
+ expect (form.invalid).toBe (true );
1415
+ });
1383
1416
});
1384
1417
1385
1418
it ('should set the model to be untouched when the model is reset' , () {
You can’t perform that action at this time.
0 commit comments