Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Commit

Permalink
v1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
aguirrel committed Mar 20, 2017
2 parents c30c0bd + eae8d38 commit b39b660
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion dist/ng-currency.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ng-currency.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-currency",
"version": "1.2.0",
"version": "1.2.1",
"main": "dist/ng-currency.js",
"description": "Directive that works in conjunction with currency filter.",
"homepage": "http://alaguirre.com",
Expand Down
13 changes: 9 additions & 4 deletions src/ng-currency.directive.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export default function ngCurrency($filter, $locale, ngCurrencySettings) {
export default function ngCurrency($filter, $locale, $timeout, ngCurrencySettings) {
return {
require: 'ngModel',
link: (scope, element, attrs, controller) => {
let { hardCap, min, max, currencySymbol, fraction } = ngCurrencySettings.defaults;
let ngRequired = ['', 'true'].indexOf(attrs.ngRequired) !== -1;
let ngRequired = attrs.required;
let active = true;

attrs.$observe('ngCurrency', (value) => {
Expand Down Expand Up @@ -31,7 +31,7 @@ export default function ngCurrency($filter, $locale, ngCurrencySettings) {
currencySymbol = value;
reformat();
});
scope.$watch(attrs.ngRequired, (value) => {
attrs.$observe('required', (value) => {
ngRequired = value;
revalidate();
});
Expand All @@ -41,6 +41,11 @@ export default function ngCurrency($filter, $locale, ngCurrencySettings) {
revalidate();
});

// HACK(cecilia-sanare): Seriously angular?
$timeout(() => {
scope.$emit('currencyRedraw');
});

controller.$parsers.push((value) => {
if (active && [undefined, null, ''].indexOf(value) === -1) {
value = clearValue(value);
Expand Down Expand Up @@ -204,4 +209,4 @@ export default function ngCurrency($filter, $locale, ngCurrencySettings) {
}
};
}
ngCurrency.$inject = ['$filter', '$locale', 'ngCurrencySettings'];
ngCurrency.$inject = ['$filter', '$locale', '$timeout', 'ngCurrencySettings'];
15 changes: 15 additions & 0 deletions test/ng-currency/ng-currency.directive.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,21 @@ describe('ngCurrency directive tests', () => {
});
});

describe('Required', () => {
beforeEach(angular.mock.inject(($rootScope, $compile, $timeout) => {
scope = $rootScope.$new();
scope.value = undefined;
scope.$digest();
element = $compile(`<input ng-currency min="1" ng-model="value" required>`)(scope);
$timeout.flush();
}));

it('should support the required attribute', () => {
expect(element.hasClass('ng-invalid')).toBeTruthy();
expect(element.hasClass('ng-invalid-min')).toBeTruthy();
});
});

describe('$pristine', () => {
it('should be pristine when initialized with a custom currencySymbol', () => {
scope.currencySymbol = '¥';
Expand Down

0 comments on commit b39b660

Please sign in to comment.