Parse & Format example loses caret position
URL for the parse & format example: https://codesandbox.io/s/10rzowm323
Bug reproduction ( ^ means caret)
(123) 12^3-1234
// backspace, then 1
(123) 131-2341^
Note that this works:
(123) 123-12^34
// backspace then 1
(123) 123-11^34
env: Windows 10, Firefox 60
Is this a bug in final-form or a bug in the example?
I used to solve this using cleaveJS, but I'm hoping for some other lighter alternative...
Sorry i fixed it - seems it's just an issue with the example code.
const normalizePhone = value => {
if (!value) return value;
const onlyNums = value.replace(/[^\d]/g, "");
if (onlyNums.length <= 3) return onlyNums;
if (onlyNums.length <= 7)
return `(${onlyNums.slice(0, 3)}) ${onlyNums.slice(3, 7)}`; // this was the culprit
return `(${onlyNums.slice(0, 3)}) ${onlyNums.slice(3, 6)}-${onlyNums.slice(
6,
10
)}`;
};
please fix the example code & close this issue :)
Fixed. Thanks!
I can still reproduce this in the codesandbox 😕
This issue should be reopened.
I can still reproduce
Reproduced here
replacing the number in the middle causes losing the caret position!
I can still reproduce
I can still reproduce