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

Value not getting cleared after submit. #338

Open
sohansarma opened this issue May 14, 2020 · 2 comments
Open

Value not getting cleared after submit. #338

sohansarma opened this issue May 14, 2020 · 2 comments

Comments

@sohansarma
Copy link

sohansarma commented May 14, 2020

Describe the bug
I am storing the value in state and after submitting the form I am clearing the state, The state is getting cleared but number in the form is not getting cleared as I see the value is already there in DOM.

`

this._mapPropsToState = function (props) {

var firstCall = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false
var inputNumber = void 0;
if (props.value) {
  inputNumber = props.value;
} else if (props.initialValue && firstCall) {
  inputNumber = props.initialValue;
} else if (_this3.props.value) {
  // just clear the value
  inputNumber = '';
} else if (_this3.state && _this3.state.formattedNumber && _this3.state.formattedNumber.length > 0) {
  inputNumber = _this3.state.formattedNumber;
} else {
  inputNumber = '';
}

var selectedCountryGuess = _this3.guessSelectedCountry(inputNumber.replace(/\D/g, ''));
var selectedCountryGuessIndex = findIndex(propEq('iso2', selectedCountryGuess.iso2), allCountries);
var formattedNumber = (0, _format_number2.default)(inputNumber.replace(/\D/g, ''), selectedCountryGuess ? selectedCountryGuess.format : null, _this3.props.autoFormat);
console.log('formattedNumber -->', formattedNumber)
return {
  selectedCountry: selectedCountryGuess,
  highlightCountryIndex: selectedCountryGuessIndex,
  formattedNumber: formattedNumber
};

};
`

Consoled formattedNumber and I see it is not getting cleared.

How I can I make it clear? @mukeshsoni

Expected behavior
Clear the input value when state is cleared.

Desktop (please complete the following information):

  • OS: [e.g. iOS] - Mac
  • Browser [e.g. chrome, safari] - Chrome
@sohansarma
Copy link
Author

I used initialValue instead of value so the issue came up. @mukeshsoni Please make sure you update the Doc
value and initialValue Both the props have the same purpose - for setting the initial value of the input programatically.

I don't see both working same for reseting.

@sohansarma sohansarma reopened this Dec 1, 2020
@sohansarma
Copy link
Author

The issue was resolved but it came up again. Was there any change in the code?

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

1 participant