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

Can't set empty value for input ( reproduction ) #804

Closed
wenzoto opened this issue Sep 26, 2018 · 6 comments
Closed

Can't set empty value for input ( reproduction ) #804

wenzoto opened this issue Sep 26, 2018 · 6 comments

Comments

@wenzoto
Copy link

wenzoto commented Sep 26, 2018

There was a similar error, but could not reproduce it.

https://codesandbox.io/s/7m6q1y8xmj

reproduction

Image from Gyazo

@cjnickel
Copy link

cjnickel commented Jan 3, 2019

Ran into this issue as well. Looks like PR #816 should fix this assuming it gets merged.

@Bereware
Copy link

Bereware commented Nov 5, 2019

This would be a temporary solution.
This error is the one that shows when you try to modify the state:
Warning: A component is changing a controlled input of type undefined to be uncontrolled

I have solved it this way, it is not recommended to use refs but ... xD

<DayPickerInput
    value={from}
    ref={(el) => (this.from = el)}
.../>
<DayPickerInput
    value={to}
    ref={(el) => (this.to = el)}
.../>
handleResetClick = () => {
        // this fixed the encapsulated input uncontrolled bug
        this.from.setState({ value: '', typedValue: '' });
        this.to.setState({ value: '', typedValue: '' });
    };

I hope this works for people who still fail.

@serban-condrea
Copy link

In order to avoid refs, I used another little hack 😅

<DayPickerInput
    value={to || ' '}
.../>

@gpbl
Copy link
Owner

gpbl commented Apr 22, 2020

This has been fixed in the latest releases - please upgrade thanks

@gpbl gpbl closed this as completed Apr 22, 2020
@owen-stellar
Copy link

Though I've upgraded to 7.4.8 I don't see this being resolved. When I clear out the value (in a blur function when the entry is deemed to be invalid) the typedValue remains the same. Is there something more that needs to be done besides simply upgrading to 7.4.8?

@tanelih
Copy link

tanelih commented Oct 22, 2020

The latest release still exhibits this problem when clearing a value that is not a valid Date.

I've played around changing the following line to also set the typed value to the given value & the problem seems to go away.

https://github.com/gpbl/react-day-picker/blob/v7/src/DayPickerInput.js#L198

if (isDate(value)) {
  newState.value = formatDate(value, format, dayPickerProps.locale);
} else {
  newState.value = value;
  newState.typedValue = value;
}

However I'm not a 100% certain this is the best solution, but it seems to work for my use case, where dates are stored in the form state as plain strings.

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