RobinHerbots / Inputmask

Input Mask plugin
https://robinherbots.github.io/Inputmask/
MIT License
6.39k stars 2.17k forks source link

Input is being filled with one of mask symbol #1487

Open artemkaint opened 7 years ago

artemkaint commented 7 years ago

I noticed strange behaviour when I input in multimask field

Example https://jsfiddle.net/artemkaint/qf5y9rn0/1/ Try to input 31 and input will be filled with value 381. After small research I've realized that code check next symbol after input, if it's mask it tries to fill one with input symbol. Second symbol is filled with one of valid values of masks (in that case it's 1) https://github.com/RobinHerbots/Inputmask/blob/3.x/dist/jquery.inputmask.bundle.js#L459 If I input 39 then 9 isn't injected because 9 isn't valid for masks (there is not 9 in third position of all masks)

without mask sorting result will be more interesting https://jsfiddle.net/artemkaint/qf5y9rn0/2/

artemkaint commented 7 years ago

I've made other researches and found out features . If we pass param "strict" = true in EventHandlers.keypressEvent from jquery event handler then we have ordinary behaviour

artemkaint commented 7 years ago

+info isComplete === true if we input symbols according mask (https://github.com/RobinHerbots/Inputmask/blob/3.x/js/inputmask.js#L1964 loop continue until symbol index instead of mask length )

RobinHerbots commented 7 years ago

@artemkaint ,

The sorting of the masks is important. Have a look at the phone.extensions and examples. Can you try with putting your phone selection into it. And see where it gets you.

With multiple masks the lenght of the mask will vary.

RobinHerbots commented 7 years ago

Ok, you convinced me, the alternation can be better. Have you played already with the keepStatic option? Ik will have a look tomorrow.

artemkaint commented 7 years ago

I've played with the keepStatic option and it does not take effect

artemkaint commented 7 years ago

+info isComplete === true if we input symbols according mask (https://github.com/RobinHerbots/Inputmask/blob/3.x/js/inputmask.js#L1964 loop continue until symbol index instead of mask length )

RobinHerbots commented 7 years ago

@artemkaint ,

So this is the mask were are testing against:

    Inputmask([
            "+7(###)###-##-##",
            "+7(6##)###-##-##",
            "+7(7##)###-##-##",
            "+371-##-###-###",
            "+370(###)##-###",
            "+375(##)###-##-##",
            "+374-##-###-###",
            "+380(##)###-##-##",
            "+358(###)###-##-##",
            "+996(###)##-##-##",
            "+373-####-####",
            "+381-##-###-####",
            "+994-##-###-##-##",
            "+49(####)###-####",
            "+49(###)###-####",
            "+49(###)##-####",
            "+49(###)##-###",
            "+49(###)##-##",
            "+49-###-###"]).mask("test5");
RobinHerbots commented 7 years ago

@artemkaint ,

I submitted some updates on the alternation logic and also you need to escape the 9 in the masks otherwise they are treated as the 9-definition