Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'master' of git://github.com/blackbarn/angular-ui

* 'master' of git://github.com/blackbarn/angular-ui:
  reset now supports defining of a reset value instead of being forced to use null
  • Loading branch information...
commit 0ffbb74ae449d92f56dcf64c7caf2a081c16398c 2 parents 5a35f7f + f7b222f
@ProLoser ProLoser authored
View
14 modules/directives/reset/reset.js 100644 → 100755
@@ -5,14 +5,22 @@ angular.module('ui.directives').directive('uiReset', ['$parse', function ($parse
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
- var aElement = angular.element('<a class="ui-reset" />');
+ var opts, aElement;
+ opts = {};
+ if (attrs.uiReset) {
+ opts = scope.$eval(attrs.uiReset);
+ if (angular.isString(opts)) {
+ opts = {resetValue: opts};
+ }
+ }
+ opts = angular.extend({resetValue: null}, opts);
+ aElement = angular.element('<a class="ui-reset" />');
elm.wrap('<span class="ui-resetwrap" />').after(aElement);
-
aElement.bind('click', function (e) {
e.preventDefault();
scope.$apply(function () {
// This lets you SET the value of the 'parsed' model
- ctrl.$setViewValue(null);
+ ctrl.$setViewValue(opts.resetValue);
ctrl.$render();
});
});
View
30 modules/directives/reset/test/resetSpec.js 100644 → 100755
@@ -32,7 +32,7 @@ describe('uiReset', function () {
element.siblings().get(0).click();
expect($.Event.prototype.preventDefault).toHaveBeenCalled();
});
- it('should clear the model and control value', function () {
+ it('should set the model value to null and clear control when no options given', function () {
scope.foo = 'bar';
var element = $compile('<input type="text" ui-reset ng-model="foo"/>')(scope);
scope.$digest();
@@ -41,5 +41,33 @@ describe('uiReset', function () {
expect(scope.foo).toBe(null);
expect(element.val()).toBe('');
});
+ it('should set the model value to the options scope variable when a string is passed in options', function () {
+ scope.foo = 'bar';
+ scope.resetTo = 'i was reset';
+ var element = $compile('<input type="text" ui-reset="resetTo" ng-model="foo"/>')(scope);
+ scope.$digest();
+ expect(element.val()).toBe('bar');
+ element.next().click();
+ expect(scope.foo).toBe('i was reset');
+ expect(element.val()).toBe('i was reset');
+ });
+ it('should set the model value to the options property resetValue when an object is passed with the resetValue property', function () {
+ scope.foo = 'bar';
+ var element = $compile('<input type="text" ui-reset="{resetValue: \'was reset\'}" ng-model="foo"/>')(scope);
+ scope.$digest();
+ expect(element.val()).toBe('bar');
+ element.next().click();
+ expect(scope.foo).toBe('was reset');
+ expect(element.val()).toBe('was reset');
+ });
+ it('should set the model value to null when an object is passed without the resetValue property', function () {
+ scope.foo = 'bar';
+ var element = $compile('<input type="text" ui-reset="{baz: \'was reset\'}" ng-model="foo"/>')(scope);
+ scope.$digest();
+ expect(element.val()).toBe('bar');
+ element.next().click();
+ expect(scope.foo).toBe(null);
+ expect(element.val()).toBe('');
+ });
});
});
Please sign in to comment.
Something went wrong with that request. Please try again.