react-phone-input-2 icon indicating copy to clipboard operation
react-phone-input-2 copied to clipboard

Need the ability to show placeholder when default country is selected but number input is empty

Open WaqqarSuleman opened this issue 3 years ago • 7 comments

Hi,

I have a requirement where I need the ability to show placeholder when default country is selected but number input is empty. Any help would be appreciated.

WaqqarSuleman avatar Dec 01 '20 09:12 WaqqarSuleman

Hi @WaqqarSuleman, Did you find a solution for this issue? I'm facing the same problem. Thanks!

MartinDesrosiers avatar Dec 17 '20 21:12 MartinDesrosiers

Hi @WaqqarSuleman, Did you find a solution for this issue? I'm facing the same problem. Thanks!

Nope.

WaqqarSuleman avatar Dec 18 '20 08:12 WaqqarSuleman

Same problem here. I cannot show the placeholder either.

instakash avatar Mar 09 '21 22:03 instakash

Bump. Same here.

xtrinch avatar May 03 '21 15:05 xtrinch

Bump

groteck avatar Sep 23 '21 15:09 groteck

+1

XxOsirisxX avatar Jun 06 '22 23:06 XxOsirisxX

Hi folks, try this:


  const [value, setValue]= useState('')
  // ...

  useEffect(() => {
    // tricky way of set as empty the phoneInput with a country code selected

    let timer = setTimeout(() => setValue('1'), 100)  // or whatever state you have, Formik, RHF...
    let timer2 = setTimeout(() => setValue(''), 200)
    return () => {
      clearTimeout(timer)
      clearTimeout(timer2)
    }
  }, [])

  // ... add value to your PhoneInput component like always...

Voilà, it works 😉

hipdev avatar Jul 14 '22 14:07 hipdev