formsy-material-ui
formsy-material-ui copied to clipboard
[FormsyText] not showing default value from ajax call
Hi, When updating the default value from ajax call the value is not being updated. Please consider to add
componentWillReceiveProps: function(nextProps) {
var value = this.props.defaultValue || this.props.value || '';
// checking that value is exist because we don't want to override user's input
if(value){
this.setState({
value: value
});
}
}
Into FormsyText
HI @0xori I may be misunderstanding your use case, but the default value is just that - the initial value, so shouldn't change. Could you give an example perhaps?
Hi @mbrookes, currently you take the defaultValue
from getInitialState()
this function is Invoked once before the component is mounted.
If I need to get my defaultValue
from a server (via ajax), it wouldn't update because getInitialState()
is already invoked, therefore, if you'll use also componentWillReceiveProps
to get the defaultValue
it will be updated even if you'll get it after the component is being mounted.
@0xori I get you. In that case, feel free to submit a PR, but please ensure it works consistently across all the form components. 👍