Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull request to add dynamic variable to show or hide "-" operator #93

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/currency-mask.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {InjectionToken} from "@angular/core";
export interface CurrencyMaskConfig {
align: string;
allowNegative: boolean;
showNegativeOperator: boolean;
allowZero: boolean;
decimal: string;
precision: number;
Expand Down
1 change: 1 addition & 0 deletions src/currency-mask.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class CurrencyMaskDirective implements AfterViewInit, ControlValueAccesso
public optionsTemplate: CurrencyMaskConfig = {
align: "right",
allowNegative: true,
showNegativeOperator: true,
allowZero: true,
decimal: ".",
precision: 2,
Expand Down
4 changes: 2 additions & 2 deletions src/input.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export class InputService {
}

applyMask(isNumber: boolean, rawValue: string, disablePadAndTrim = false): string {
let {allowNegative, decimal, precision, prefix, suffix, thousands, min, max, inputMode} = this.options;
let {allowNegative, showNegativeOperator, decimal, precision, prefix, suffix, thousands, min, max, inputMode} = this.options;

rawValue = isNumber ? new Number(rawValue).toFixed(precision) : rawValue;
let onlyNumbers = rawValue.replace(this.ONLY_NUMBERS_REGEX, "");
Expand Down Expand Up @@ -139,7 +139,7 @@ export class InputService {
}

let isZero = newValue == 0;
let operator = (isNegative && allowNegative && !isZero) ? "-" : "";
let operator = (isNegative && allowNegative && showNegativeOperator && !isZero) ? "-" : "";
return operator + prefix + newRawValue + suffix;
}

Expand Down
1 change: 1 addition & 0 deletions test/currency-mask-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('Testing CurrencyMaskConfig', () => {
thousands: '.',
decimal: ',',
allowNegative: false,
showNegativeOperator: false,
nullable: false
}];

Expand Down
1 change: 1 addition & 0 deletions test/input-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('Testing InputHandler', () => {
thousands: '.',
decimal: ',',
allowNegative: false,
showNegativeOperator: false,
nullable: false,
align: 'right',
allowZero: true,
Expand Down
1 change: 1 addition & 0 deletions test/input-service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ describe('Testing InputService', () => {
thousands: '.',
decimal: ',',
allowNegative: false,
showNegativeOperator: false,
nullable: false,
align: 'right',
allowZero: true,
Expand Down