Amphtml: amp-inputmask: Leading Zero been stripped when I paste into field

Created on 3 Apr 2019  路  3Comments  路  Source: ampproject/amphtml

What's the issue?

When I paste the text 00005127120 into the input, it should displays 000.051.271-20, but is showing 005.127.120. If I paste 00245127120 it shows 245.127.120.

How do we reproduce the issue?

You can reproduce it here: https://codepen.io/egoncalves/pen/MRKymb
step-by-step instructions for reproducing the issue:

  1. Step 1: Copy the text 00005127120
  2. Step 2: Paste it into input

What browsers are affected?

All browsers

High Priority Bug

Most helpful comment

After investigating, I found that the custom mask in amp-inputmask was over-optimized for the telephone number use case. I propose we add a mask-strip-zeros attribute to allow document authors to opt-in to removing the zeros. This is not backward compatible, but usage is still low and the behavior only applies on paste which is not a critical flow that people will be depending on to remain the same. This will avoid surprising future users and document authors.

All 3 comments

Hi @cvializ
As amp-inputmask uses RobinHerbots' Inputmask (release 4.0.4), I tested it with same version, and it's working.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input id="cpf" name="cpf"/>
<br/>
<script src="https://code.jquery.com/jquery-1.10.0.min.js"></script>
<script src="https://rawgit.com/RobinHerbots/Inputmask/4.0.4/dist/jquery.inputmask.bundle.js"></script>
<script>
    $("#cpf").inputmask("999.999.999-99");
</script>
</body>
</html>

Thanks for sharing your experience and for the detailed example! I am able to reproduce and I found the root cause. I'll prioritize it for work soon

After investigating, I found that the custom mask in amp-inputmask was over-optimized for the telephone number use case. I propose we add a mask-strip-zeros attribute to allow document authors to opt-in to removing the zeros. This is not backward compatible, but usage is still low and the behavior only applies on paste which is not a critical flow that people will be depending on to remain the same. This will avoid surprising future users and document authors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sryze picture sryze  路  3Comments

mrjoro picture mrjoro  路  3Comments

choumx picture choumx  路  3Comments

edhollinghurst picture edhollinghurst  路  3Comments

torch2424 picture torch2424  路  3Comments