formsy-material-ui icon indicating copy to clipboard operation
formsy-material-ui copied to clipboard

[FormsyText] not showing default value from ajax call

Open 0xori opened this issue 8 years ago • 3 comments

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

0xori avatar May 01 '16 13:05 0xori

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?

mbrookes avatar May 01 '16 14:05 mbrookes

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 avatar May 01 '16 15:05 0xori

@0xori I get you. In that case, feel free to submit a PR, but please ensure it works consistently across all the form components. 👍

mbrookes avatar May 01 '16 16:05 mbrookes