Skip to content

Commit

Permalink
fix(backspace): Functionality for backspacing beginning number (edge …
Browse files Browse the repository at this point in the history
…case)
  • Loading branch information
ElliotGM committed Sep 6, 2018
1 parent d5b1273 commit 4e2128d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion demo/demo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DemoComponent {
public form: FormGroup;
public value: number;
public ngxCurrencyOptions = {
prefix: 'R$ ',
prefix: '',
thousands: '.',
decimal: ',',
allowNegative: false,
Expand Down
16 changes: 14 additions & 2 deletions src/input.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,23 @@ export class InputService {
selectionStart = this.rawValue.length - this.options.suffix.length;
}

const move = this.rawValue.substr(selectionStart - 1, 1).match(/\d/) ? 0 : 1;
let move = this.rawValue.substr(selectionStart - 1, 1).match(/\d/) ? 0 : -1;
move = (
(
keyCode == 8 &&
selectionStart - 1 === 0 &&
!(this.rawValue.substr(selectionStart, 1).match(/\d/))
) ||
(
(keyCode == 46 || keyCode == 63272) &&
selectionStart === 0 &&
!(this.rawValue.substr(selectionStart + 1, 1).match(/\d/))
)
) ? 1 : move;
selectionEnd = keyCode == 46 || keyCode == 63272 ? selectionEnd + 1 : selectionEnd;
selectionStart = keyCode == 8 ? selectionStart - 1 : selectionStart;
this.rawValue = this.rawValue.substring(0, selectionStart) + this.rawValue.substring(selectionEnd, this.rawValue.length);
this.updateFieldValue(selectionStart - move);
this.updateFieldValue(selectionStart + move);
}

updateFieldValue(selectionStart?: number): void {
Expand Down

0 comments on commit 4e2128d

Please sign in to comment.