Reputation: 437
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"}
Upvotes: 0
Views: 1201
Reputation: 46441
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>
Upvotes: 1