首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Redux-Form onclick处理程序

Redux-Form onclick处理程序
EN

Stack Overflow用户
提问于 2018-04-16 00:28:38
回答 1查看 1.3K关注 0票数 0

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

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

使用onSubmit处理程序很容易做到这一点,但我只需要为提交保留提交。

帮帮我!

谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-04-16 14:36:51

你也可以试试这个。

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49844234

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档