Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modified @blackbarn changes to uiReset

To simplify things, uiReset does not take an
options object but instead just the new value
  • Loading branch information...
commit 2afd410e70f8a385b8dcaa4803bc8891626aab78 1 parent 0ffbb74
Dean Sofer ProLoser authored
1  CHANGELOG.md
View
@@ -12,6 +12,7 @@
* The **ui-keypress** can now be used to `$event.preventDefault()` as expected
* Multiple combinations are separated by spaces, while multi-key combos are separated by dashes: `'enter alt-space 13-shift':'whatever()'`
* The string-notation (__a and be or c and d__) has been dropped completely
+* Can now pass (or globally define) the value uiReset resets to
## v0.2.0
* Unit tests. Unit tests. Unit tests.
21 modules/directives/reset/reset.js
View
@@ -1,26 +1,23 @@
/**
* Add a clear button to form inputs to reset their value
*/
-angular.module('ui.directives').directive('uiReset', ['$parse', function ($parse) {
+angular.module('ui.directives').directive('uiReset', ['ui.config', function (uiConfig) {
+ var resetValue = null;
+ if (uiConfig.reset !== undefined)
+ resetValue = uiConfig.reset;
return {
require: 'ngModel',
link: function (scope, elm, attrs, ctrl) {
- 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);
+ var aElement;
aElement = angular.element('<a class="ui-reset" />');
elm.wrap('<span class="ui-resetwrap" />').after(aElement);
aElement.bind('click', function (e) {
+ if (attrs.uiReset) {
+ resetValue = scope.$eval(attrs.uiReset);
+ }
e.preventDefault();
scope.$apply(function () {
- // This lets you SET the value of the 'parsed' model
- ctrl.$setViewValue(opts.resetValue);
+ ctrl.$setViewValue(resetValue);
ctrl.$render();
});
});
18 modules/directives/reset/test/resetSpec.js
View
@@ -51,23 +51,5 @@ describe('uiReset', function () {
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.