jaridmargolin / formatter.js

Format html inputs to match a specified pattern
http://firstopinion.github.io/formatter.js
2.48k stars 235 forks source link

Opera Mobile doubles every char on input #62

Open viteksafronov opened 10 years ago

viteksafronov commented 10 years ago

I have a classic pattern for credit cards pattern: '{{9999}} {{9999}} {{9999}} {{9999}} {{99}}' When I try to enter the number in Opera Mobile, every digit is entered twice, so I have to delete an extra char.

kot-lex commented 10 years ago

That's a well-known bug. Opera mobile completely ignores preventDefault/return false for keydown and keypress events. There is a simple example which illustrates that behaviour: http://jsfiddle.net/5zrhutra/ Opera mobile is an outdated browser and it won't be updated anymore. Personally, I came to a decision just not to add formatter for opera:

var isOperaMobile = navigator.userAgent.toLowerCase().indexOf('opera mobi/') !== -1;
if (!isOperaMobile) {
    new Formatter(...);
}
kot-lex commented 10 years ago

All these bugs can be reproduced in Opera Mobile Emulator http://www.opera.com/ru/developer/mobile-emulator

jaridmargolin commented 10 years ago

Unfortunately I do not see a solution if preventDefault is ignored. The library depends on this functionality. Perhaps an error or warning should be thrown when using an unsupported browser.

Browser sniffing is an ugly solution, but with so many inconsistencies in browser keyboard handling, it may be the best solution.