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

Commit

Permalink
fix(ngModel): ensure post-reset validation works properly
Browse files Browse the repository at this point in the history
Closes #1605
  • Loading branch information
matsko authored and rkirov committed Jan 14, 2015
1 parent 5205c14 commit 6bf7eaa
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/directive/ng_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ class NgModel extends NgControl implements AttachAware {
*/
void reset() {
markAsUntouched();
_processViewValue(_originalValue);
modelValue = _originalValue;
_processViewValue(_originalValue);
}

void onSubmit(bool valid) {
Expand Down
33 changes: 33 additions & 0 deletions test/directive/ng_model_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1380,6 +1380,39 @@ void main() {
expect(model.modelValue).toEqual('animal');
expect(model.viewValue).toEqual('animal');
});

it('should revalidate itself after the form is reset ', (Scope scope) {
_.compile('<form name="myForm" novalidate>' +
' <input type="text" ng-required="true" ng-model="inputValue" probe="i">' +
'</form>');

scope.apply();

var form = _.rootScope.context['myForm'];
var formElement = form.element.node;

var input = _.rootScope.context['i'].directive(NgModel);
var inputElement = input.element.node;

expect(form.valid).toBe(false);
expect(form.invalid).toBe(true);

inputElement.value = 'a special value';
_.triggerEvent(inputElement, 'input');
scope.apply();

expect(form.valid).toBe(true);
expect(form.invalid).toBe(false);

form.reset();
//we need to run apply to properly update the input dom element
scope.apply();

expect(scope.context['inputValue']).toBe(null);
expect(inputElement.value.length).toBe(0);
expect(form.valid).toBe(false);
expect(form.invalid).toBe(true);
});
});

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

0 comments on commit 6bf7eaa

Please sign in to comment.