Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reset value for phone input #72

Open
GSolari79 opened this issue Oct 26, 2018 · 6 comments
Open

How to reset value for phone input #72

GSolari79 opened this issue Oct 26, 2018 · 6 comments

Comments

@GSolari79
Copy link

I would like to reset the value of the PhoneInput. Does anyone know how to do it?

Really appreciated.

@Valentinishe
Copy link

same problem)
I want to create a controlled component

@rickerbh
Copy link

rickerbh commented Jun 2, 2019

A hacky workaround, but if you provide a key prop to the component you can change it to force a new component to be created/mounted. It doesn't strictly reset the instance you have, but it gives the appearance of resetting.

@khushbuthakur
Copy link

this.phone.state.inputValue = "";
this.phone.state.formattedNumber = "";

This resets the phone number

@ncuthbert
Copy link

If you want to maintain the current dialling code on the input field, the following works for me:

  1. I grab the ISO code from the input
  2. Set the iso2 value to undefined
  3. Call selectCountry with the saved ISO code
const ISOCode = this.phoneInput.getISOCode()
this.phoneInput.setState({ iso2: undefined }, () => {
  this.phoneInput.selectCountry(ISOCode)
})

@zuraizzafar
Copy link

If you are working with functional component you can use:
phoneInput.current?.setState({number: 0})

@leira-sanchez
Copy link

If you are working with functional component you can use: phoneInput.current?.setState({number: 0})

setState does not seem to be defined in the type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants