我正在使用Redux表单和Redux Material UI包。通常,当我运行这样的代码时,它可以工作,但由于某种原因,它无法获得TextField
的值。有谁知道这里发生了什么?
我的console.log
声明刚回来{special_instructions: undefined}
import React from 'react';
import { connect } from 'react-redux';
import { Field, reduxForm } from 'redux-form/immutable';
/**
* Components
*/
import TextField from 'material-ui/TextField';
import RaisedButton from 'material-ui/RaisedButton';
export class EditRequestForm extends React.Component { // eslint-disable-line react/prefer-stateless-function
constructor(props) {
super(props);
this.onSubmit = this.onSubmit.bind(this);
}
cancel() {
this.props.handleCancelEdit();
}
onSubmit(formProps) {
const request = {
special_instructions: formProps.get('special_instructions'),
};
console.log('request', request);
}
render() {
// console.log(this.props.request);
const { handleSubmit, pristine, reset, submitting, errors } = this.props
let request = this.props.request;
return (
<form className="page-form__wrapper page-body__wrapper read-request-page">
<TextField
name="area_instructions"
multiLine={true}
fullWidth={true}
id="area_instructions"
defaultValue={request.area_instructions}
/>
<div className="page-form__block draft-field bg-grey">
<RaisedButton
primary={true}
onTouchTap={handleSubmit(this.onSubmit)}
label="Update"
/>
<RaisedButton
secondary={true}
onTouchTap={handleSubmit(::this.cancel)}
label="Cancel"
/>
</div>
</form>
);
}
}
function mapDispatchToProps(dispatch) {
return {
dispatch,
};
}
export default reduxForm({
form: 'editRequest',
})(connect(mapDispatchToProps)(EditRequestForm));