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

Country change does not trigger onChange event

Open Kerhael opened this issue 4 years ago • 1 comments

Hi,

We have a form where we have a phone input and a country input.
When we select a country, we update the phone input with the selected new country.

Here is our current issue: 1- enter an invalid phone number in phone input => our validation fails and the "invalid-number" class is added to the input
2- select another country from the country input
=> issue: the phone input country is updated, the input is cleared BUT the "invalid-number" class is still here

This happens because the onChange event is not called on country change.

We are using phone input within a controller, so as a workaround we set a key key={selectedCountry} attribute on the controller.

Anyway thanks for this great library, it is of great use for us!

Kerhael avatar Jul 02 '21 06:07 Kerhael

Moreover, if you combine a pre-set country with the required input prop, you can submit the form but onChange was never called, so our model still has an undefined

danielfx90 avatar Jul 09 '21 13:07 danielfx90