我有一个redux-form,我想添加一个按钮,这个按钮不会提交,但会详细说明填充其他字段的字段。问题是如何在onclick处理程序中访问表单的字段值?
我试图从store.getState恢复它们,但并不是那么简单地访问状态。
使用onSubmit处理程序很容易做到这一点,但我只需要为提交保留提交。
帮帮我!
谢谢
发布于 2018-04-16 14:36:51
你也可以试试这个。
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { Field, reduxForm } from 'redux-form'
class Test extends Component {
static contextTypes = {
store: PropTypes.object,
}
constructor(props) {
super(props)
this.state = {
}
this.getFormValues = this.getFormValues.bind(this)
}
getFormValues() {
////// at any function try this
const { store } = this.context
const state = store.getState()
console.log(state.form.test.values)//you will get form values here
}
render() {
return(<div>Redux Form Goes here</div>)
}
}
export default reduxForm({
form: 'test', // a unique identifier for this form
destroyOnUnmount: true,
})(Test)https://stackoverflow.com/questions/49844234
复制相似问题