jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers. React and Vue components also included.
https://intl-tel-input.com
MIT License
7.69k stars 1.95k forks source link

Strict mode by length is not working, after second focus #1817

Closed creative-guy closed 1 month ago

creative-guy commented 2 months ago

https://intl-tel-input.com/examples/strict-mode.html

If you focus input, type something, get focus away, an then focus again, length is no more capped.

rashadmehtab commented 2 months ago

I have checked, and everything is working on my end. Could you please provide more details about the issue you're facing? Sharing the relevant code would be helpful as well.

creative-guy commented 2 months ago

Check here https://intl-tel-input.com/examples/strict-mode.html

Write some number, then put focus in between digits, and you would be able to break the mask

jackocnr commented 2 months ago

This is working as intended. I recently changed strictMode so it only blocks characters if the cursor is at the end, which will be the case the majority of the time. This was to fix the issue when if the user mistyped their country dial code, and then tried to go back and fix it, they were blocked from doing so because the number entered for the currently selected (incorrect) country was already at its max length: https://github.com/jackocnr/intl-tel-input/issues/1777

It would be too complicated to fix it so that it checks if adding the digit could potentially lead to a country change - that's too much complexity for this edge case, and I'd rather keep it simple.

Thanks for raising the point tho. I hope that makes sense. I'll close this for now.

creative-guy commented 1 month ago

Really doesn't make sense. What is the point of this strict mode mask, if it doesn't working in certain circumstances? Maybe at least do so, that cursor in the input would be automatically placed at the end, with no chance placing in between digits. And country change, should cut redundant digits I guess.

jackocnr commented 1 month ago

Ok I'll reopen this. I'm happy for the logic to be updated to the following:

When the user enters a new character: if the number is already at max length, then only allow the character if it changes the selected country. (or if they're adding a plus at the beginning)

I don't have time to implement this myself right now, but would welcome a pull request that added this functionality.

NOTE: I don't want to mess with the user's cursor position or start deleting their digits or anything like that, as I think the user might find that confusing.

jackocnr commented 1 month ago

Fix released in v24.5.1. Let me know if you have any problems.