estelle / input-masking

Framework agnostic accessible input masking library
MIT License
485 stars 96 forks source link

Doesn't play well with form fields added by client-side scripting #29

Open o-alquimista opened 3 years ago

o-alquimista commented 3 years ago

The mask works for the first <input[class=masked]> added by scripting (on page load), but any other added later doesn't have it. The input elements come from a template. This is a simplified example:

<template id="phoneTemplate">
  <div>
    <label for="">Phone</label>
    <input type="tel" id="" name="" placeholder="99 99999-9999" class="masked" pattern="\d{2} \d{5}-\d{4}" required="required" value="">
  </div>
</template>

The empty attributes above are defined in scripting.

Here's how it looks: Captura de tela_2021-07-27_12-17-28

Here's a fiddle that reproduces it: https://jsfiddle.net/43h9vkot/8/ I'm working on a solution for this.