Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 6bf7eaa

Browse files
matskorkirov
authored andcommitted
fix(ngModel): ensure post-reset validation works properly
Closes #1605
1 parent 5205c14 commit 6bf7eaa

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/directive/ng_model.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ class NgModel extends NgControl implements AttachAware {
7474
*/
7575
void reset() {
7676
markAsUntouched();
77-
_processViewValue(_originalValue);
7877
modelValue = _originalValue;
78+
_processViewValue(_originalValue);
7979
}
8080

8181
void onSubmit(bool valid) {

test/directive/ng_model_spec.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,39 @@ void main() {
13801380
expect(model.modelValue).toEqual('animal');
13811381
expect(model.viewValue).toEqual('animal');
13821382
});
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+
});
13831416
});
13841417

13851418
it('should set the model to be untouched when the model is reset', () {

0 commit comments

Comments
 (0)