0

I try to set my values in my redux-form, but the input doesn't show the value. Can somebody please help me?

This is my code.

import React from "react";
import { Field, reduxForm } from "redux-form";
import {connect} from 'react-redux';
import {renderTextField, renderField, validate, warn} from "../../../Components/Forms/renders"
class SyncValidationForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      errors: {}
    }
  }

  render() {
  const { handleSubmit, pristine, reset, submitting } = this.props;
  return (
    <form onSubmit={handleSubmit}>
      <div className="col-sm-12">
        <h4 className="info-text"> Let's start with the basic details</h4>
      </div>
      <Field name="what.title.value" type="text" component={renderField} label="Titel" />

    </form>
  );
}
}
SyncValidationForm = reduxForm({
  form: 'insertstart',
  enableReinitialize: true,
  validate, // <--- validation function given to redux-form
  warn
})(SyncValidationForm);

const mapStateToProps = state => {
  return {
    initialValues: state.items.item,

  }
}

export default connect(mapStateToProps)(SyncValidationForm)

I my console log I see this by console.log(this.props);

initialValues:{what.title.value: "test"}

2 Answers 2

1

You need to pass the initial values as an object, so instead of

what.title.value: "test"

your state.items.item should look like:

{ what: { title: { value: "test" } } }

See here for a working example.

Sign up to request clarification or add additional context in comments.

Comments

1

Always use change function to bind data in redux-form fields

componentWillMount() {
    const { change } = this.props
    change('basicDetails', 'sdfuhdsuiafghfudsauifhdsuifhuiads') // this will bind name with basicDetails
}

<form onSubmit={handleSubmit}>
      <div className="col-sm-12">
        <h4 className="info-text"> Let's start with the basic details</h4>
      </div>
      <Field name="basicDetails" type="text" component={renderField} label="Titel" />
    </form>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.