Search code examples
reactjsmaterialize

Initialize active class on Materialize form when form is prepopulated


I'm using materialise with reactjs. When I populate a form with data from the database the value is set however the label transition javascript which adds the active class isn't triggered. This means the value of the form is ontop of the label. Materialize docs suggests using some jquery to get it to trigger, however, putting this jquery in componentWillReceiveProps after this.setState doesn't seem to work. I'm new to Reactjs so help is appreciated.

componentWillReceiveProps(nextProps) {
  var profileCandidate = nextProps.profileCandidate;
  var firstName = profileCandidate && profileCandidate.name && profileCandidate.name.first;

  this.setState({
    'name.first': firstName,
  });

  $(document).ready(function() {
    Materialize.updateTextFields();
  });
}

Solution

  • Are you using react materialize ? I do not think you will be needing such jquery logic to get fired on update if you are using react version of materialize. Thanks