Reactjs Redux表单onclick处理程序

Reactjs Redux表单onclick处理程序,reactjs,redux-form,Reactjs,Redux Form,我有一个redux表单,我想添加一个按钮,该按钮不提交,但详细说明字段以填充其他字段。问题是如何在onclick处理程序中访问表单的字段值 我试图从store.getState恢复它们,但访问状态并不是那么简单 使用onSubmit处理程序进行此操作很容易,但我需要保留submit仅用于submit 救救我 谢谢你也可以试试这个 import PropTypes from 'prop-types' import React, { Component } from 'react' import {

我有一个redux表单,我想添加一个按钮,该按钮不提交,但详细说明字段以填充其他字段。问题是如何在onclick处理程序中访问表单的字段值

我试图从store.getState恢复它们,但访问状态并不是那么简单

使用onSubmit处理程序进行此操作很容易,但我需要保留submit仅用于submit

救救我


谢谢你也可以试试这个

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)
从“道具类型”导入道具类型
从“React”导入React,{Component}
从“redux form”导入{Field,reduxForm}
类测试扩展了组件{
静态上下文类型={
存储:PropTypes.object,
}
建造师(道具){
超级(道具)
此.state={
}
this.getFormValues=this.getFormValues.bind(this)
}
getFormValues(){
//////在任何功能中,请尝试此功能
const{store}=this.context
const state=store.getState()
console.log(state.form.test.values)//您将在这里获得表单值
}
render(){
返回(此处是Redux表单)
}
}
导出默认reduxForm({
表单:“test”,//此表单的唯一标识符
destroyOnUnmount:是的,
})(测试)

可以显示一些代码吗?可以使用FormValuesSelect()获取formValues。。。请参考redux表单文档…按建议完成!谢谢