0
これは私のコンポーネントです - 初期値を読み込めません - フォームが送信されたときに検証エラーが発生し、初期値を更新するさまざまな方法が試されましたが、私はここで何が欠けていますか?既存の値を小道具として渡す方法は?reduxフォームの初期値 - エラーが発生しました
import React, { PropTypes, Component } from 'react';
import { reduxForm } from 'redux-form';
import { Link } from 'react-router';
import * as actions from '../../actions/myactions';
class Component extends Component {
constructor(props) {
super(props);
this.handleFormSubmit = this.handleFormSubmit.bind(this);
}
componentDidMount() {
this.props.getapidata(param);
}
handleFormSubmit({ email, name }) {
this.props.createNewvalues(url, {
email: emailval,
name: nameval,
}) :
}
renderAlert() {
//blah
}
render() {
const email = this.props.apiData && this.props.apiData.email ? this.props.apiData.email : [];
const fname = this.props.apiData && this.props.apiData.fname ? this.props.apiData.fname : [];
const initialvalues = {
email: email_from_api,
CCemail: name_from_api,
};
const { handleSubmit, fields: { email, name } } = this.props;
return (
<div>
<div>
<form onSubmit={handleSubmit(this.handleFormSubmit)}>
<fieldset>
<div>
<input value={emailsval} id="email" {...email} type="email"} required multiple />
<label className="input-label" htmlFor="Email">To</label>
{ email.touched && email.error && <div> { email.error } </div> }
</div>
</fieldset>
<fieldset>
<div>
<input value={nameval} id="name" {...name} type="email"} multiple />
<label className="input-label" htmlFor="name">name (optional)</label>
{ name.touched && name.error && <div> { name.error } </div> }
</div>
</fieldset>
</form>
</div>
</div>
);
}
}
function validate(formProps) {
const errors = {};
if (!formProps.email) {
}
if (!formProps.name) {
}
return errors;
}
function mapStateToProps(state) {
return {
responseData: state.actions.responseData,
initialValues: state.actions.apidata,
};
}
export default reduxForm({
form: 'myform',
enableReinitialize: true,
fields: [
'email',
'name',
],
validate,
}, mapStateToProps, actions)(Component);
あなたは小道具としてinitialValuesを追加しようとしましたか?あなたは 'enableReinitialize'の隣に置くか、またはそれらをpropsとして渡すことができます。 – BHubbard