react-final-form icon indicating copy to clipboard operation
react-final-form copied to clipboard

Parse & Format example loses caret position

Open devgaebal opened this issue 8 years ago • 9 comments

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...

devgaebal avatar May 21 '18 14:05 devgaebal

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 :)

devgaebal avatar May 21 '18 14:05 devgaebal

Fixed. Thanks!

erikras avatar May 21 '18 14:05 erikras

I can still reproduce this in the codesandbox 😕

karolis-sh avatar Oct 04 '18 11:10 karolis-sh

This issue should be reopened.

taschetto avatar May 28 '19 14:05 taschetto

I can still reproduce

michael-land avatar Aug 25 '19 06:08 michael-land

Reproduced here

myagoo avatar Feb 03 '20 15:02 myagoo

replacing the number in the middle causes losing the caret position!

mihanizm56 avatar Jun 08 '20 14:06 mihanizm56

I can still reproduce

devthiago avatar Jun 23 '20 19:06 devthiago

I can still reproduce

MakaryHryshkin avatar Apr 01 '21 11:04 MakaryHryshkin