react-redux-form icon indicating copy to clipboard operation
react-redux-form copied to clipboard

handleLoad makes the field invalid

Open anujgakhar opened this issue 7 years ago • 2 comments

The Problem

Control components' handleLoad() making the field invalid as there is no defaultValue (undefined). This happens when I have fired an onChange(value) already from my custom components' componentdidMount. But since Control's componentDidMount runs after the custom component, it dispatches a setErrors()as there is no defaultValue

Steps to Reproduce

I have a custom dropdown which turns into a label if there is only one option to show. So in the componentDidMount of my custom component, I have this code

if (options && options.length === 1) { this.props.onChange(options[0].value); }

This seems to work OK, but the field stays invalid in the store, as this is a required field.

Expected Behavior

After dispatching onChange, the field should become valid.

Actual Behavior

The field stays invalid in the store.

anujgakhar avatar Sep 12 '18 16:09 anujgakhar

Do you have a fix? I welcome any PRs.

davidkpiano avatar Sep 12 '18 16:09 davidkpiano

I don’t have a fix yet - just want to know what would the fix be ? Should the handleLoad pick up value as well, in addition to defaultValue ?

On 12 Sep 2018, at 17:36, David Khourshid [email protected] wrote:

Do you have a fix? I welcome any PRs.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

anujgakhar avatar Sep 12 '18 16:09 anujgakhar