Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

fix backspace event for android #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions src/mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ angular.module('ui.mask', [])

function keydownHandler(e) {
/*jshint validthis: true */
var isKeyBackspace = e.which === 8,
var isKeyBackspace = e.which === 8 || e.which === 229,
caretPos = getCaretPosition(this) - 1 || 0; //value in keydown is pre change so bump caret position back to simulate post change

if (isKeyBackspace) {
Expand Down Expand Up @@ -534,7 +534,7 @@ angular.module('ui.mask', [])

isKeyLeftArrow = eventWhich === 37,
// Necessary due to "input" event not providing a key code
isKeyBackspace = eventWhich === 8 || (eventType !== 'keyup' && isDeletion && (caretPosDelta === -1)),
isKeyBackspace = eventWhich === 8 || eventWhich === 229 || (eventType !== 'keyup' && isDeletion && (caretPosDelta === -1)),
isKeyDelete = eventWhich === 46 || (eventType !== 'keyup' && isDeletion && (caretPosDelta === 0) && !wasSelected),
// Handles cases where caret is moved and placed in front of invalid maskCaretMap position. Logic below
// ensures that, on click or leftward caret placement, caret is moved leftward until directly right of
Expand All @@ -550,6 +550,7 @@ angular.module('ui.mask', [])
}

if (isKeyBackspace && preventBackspace) {
preventBackspace = false;
iElement.val(maskPlaceholder);
// This shouldn't be needed but for some reason after aggressive backspacing the controller $viewValue is incorrect.
// This keeps the $viewValue updated and correct.
Expand Down