feat(FormController): add $rollbackViewValue to rollback all controls

Currently it is possible to use `ngModelOptions` to pend model updates until form is submitted, but in case the user wants to reset the form back to its original values he must call `$rollbackViewValue` on each input control in the form. This commit adds a `$rollbackViewValue` on the form controller in order to make this operation easier, similarly to `$commitViewValue`.

Closes #7595
This commit is contained in:
Shahar Talmi
2014-05-26 11:09:46 +03:00
committed by rodyhaddad
parent d2963ad265
commit 85b77314ed
2 changed files with 53 additions and 0 deletions

View File

@@ -206,6 +206,42 @@ describe('form', function() {
});
});
describe('rollback view value', function () {
it('should trigger rollback on form controls', function() {
var form = $compile(
'<form name="test" ng-model-options="{ updateOn: \'\' }" >' +
'<input type="text" ng-model="name" />' +
'<button ng-click="test.$rollbackViewValue()" />' +
'</form>')(scope);
scope.$digest();
var inputElm = form.find('input').eq(0);
changeInputValue(inputElm, 'a');
expect(inputElm.val()).toBe('a');
browserTrigger(form.find('button'), 'click');
expect(inputElm.val()).toBe('');
dealoc(form);
});
it('should trigger rollback on form controls with nested forms', function() {
var form = $compile(
'<form name="test" ng-model-options="{ updateOn: \'\' }" >' +
'<div class="ng-form" name="child">' +
'<input type="text" ng-model="name" />' +
'</div>' +
'<button ng-click="test.$rollbackViewValue()" />' +
'</form>')(scope);
scope.$digest();
var inputElm = form.find('input').eq(0);
changeInputValue(inputElm, 'a');
expect(inputElm.val()).toBe('a');
browserTrigger(form.find('button'), 'click');
expect(inputElm.val()).toBe('');
dealoc(form);
});
});
describe('preventing default submission', function() {
it('should prevent form submission', function() {