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

'initializeForm' take affect only once #495

Closed
liqili opened this issue Jan 4, 2016 · 13 comments
Closed

'initializeForm' take affect only once #495

liqili opened this issue Jan 4, 2016 · 13 comments

Comments

@liqili
Copy link

liqili commented Jan 4, 2016

I tried to use the function to reset form values,but it had no affect except the first call.I note that the INITIALIZE action was dispatched.

@erikras
Copy link
Member

erikras commented Jan 4, 2016

You'll have to share some example code.

@liqili
Copy link
Author

liqili commented Jan 4, 2016

In the function 'componentWillMount',call function 'initializeForm' like this:
initData = {
"appId":result.envDataMap.appIds[0].code,
"srcenv": result.envDataMap.envIds[0].code,
"destenv": result.envDataMap.envIds[0].code}
this.props.initializeForm(initData);
It take affect,However,when click the reset button, the code below can not refresh the DOM.I also note that the value of form item was changed.The form item I used is 'Combobox' in react-widgets.But I think it has nothing to do with the item type.It resulted the same when I used the 'input' tag as form item.
resetFormValue(){
this.props.initializeForm(initData);
}

@erikras
Copy link
Member

erikras commented Jan 4, 2016

To reset back to what you initialized to, you should use this.props.resetForm().

@liqili
Copy link
Author

liqili commented Jan 5, 2016

Thanks erikras very much.If using the prop 'initialValues' to initialize the form,this.props.resetForm() can reset form successfully.I want to initialize the form dynamically,unfortunately,I used function 'initializeForm' to initialize the form,then this.props.resetForm() can not reset form successfully.In addition,I also note that the property 'defaultValue' of form field object is 'undefined' when calling this.props.resetForm().

@erikras
Copy link
Member

erikras commented Jan 5, 2016

Setting initialValues does nothing different from this.props.initializeForm(). I'm not sure what you mean by "dynamically". I would recommend using redux-devtools to see what action is getting dispatched and how that is affecting the state.

@liqili
Copy link
Author

liqili commented Jan 6, 2016

I see,initialValues and this.props.initializeForm() will dispatch the same action.However,after 'action=redux-form/INITIALIZE',the fields objects are not the same in the two initial ways.Please see the below('defaultValue' /'initialValue' property is not the same):
1、By setting initialValues:

{active: false
checked: undefined
defaultChecked: false
defaultValue: "SFPB"
dirty: false
error: undefined
initialValue: "SFPB"
invalid: false
name: "appId"
onBlur: (event)
onChange: (event)
onDragStart: (event)
onDrop: (event)
onFocus: ()
onUpdate: (event)
pristine: true
touched: false
valid: true
value: "SFPB"
visited: false
__proto__: Object
}

2、By calling initializeForm() :

{active: false
checked: undefined
defaultChecked: false
defaultValue: undefined
dirty: false
error: undefined
initialValue: undefined
invalid: false
name: "appId"
onBlur: (event)
onChange: (event)
onDragStart: (event)
onDrop: (event)
onFocus: ()
onUpdate: (event)
pristine: true
touched: false
valid: true
value: "SFPB"
visited: false
__proto__: Object
}

@erikras
Copy link
Member

erikras commented Jan 6, 2016

Yes, you are correct. I should probably fix that inconsistency.

erikras added a commit that referenced this issue Jan 7, 2016
…ould come from the state first, props second.
@erikras
Copy link
Member

erikras commented Jan 7, 2016

Fix published in v4.1.1.

@liqili
Copy link
Author

liqili commented Jan 12, 2016

Thanks erikras.

@liqili liqili closed this as completed Jan 12, 2016
@linlinfly
Copy link

I got the same problems in v3.1.0

@gustavohenke
Copy link
Collaborator

@linlinfly It's been 2+ years since the last time this was an issue.
Please update Redux Form and try again.

@linlinfly
Copy link

@gustavohenke thank you.

@lock
Copy link

lock bot commented Apr 27, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators Apr 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants