【问题标题】:Setting input fields touched equal false in redux-form在 redux-form 中设置输入字段 touch 等于 false
【发布时间】:2019-02-01 07:31:06
【问题描述】:

我有redux-form 我有输入字段,当它被触摸时它会显示错误,如果有的话。现在我想在重新加载页面时将输入字段的 touched 属性重置为false。我该怎么做?

我使用redux-persist 来保持状态,所以我必须明确地这样做,所以我需要在componentDidMount 中将touched 属性设置为false。

【问题讨论】:

  • 您尝试过动作创建者吗? redux-form.com/8.1.0/docs/api/actioncreators.md/…
  • 不,我如何使用它,我是 redux-form 的新手
  • 我想我想在componentDidMount中使用untouch
  • 要不要这样用 this.props.untouch('formName', 'fieldName')
  • 是的,我知道了,我必须按照上面的方式使用它

标签: reactjs redux redux-form


【解决方案1】:

有一段时间没有接触redux-form,所以请耐心等待我的示例代码中的任何问题。

Redux-form 的 action creators 可以正常用作 dispatcher。你只需要导入action并在mapDispatchToProps中使用即可:

import { untouch } from 'redux-form/actions'

...
componentDidMount() {
    const fieldArray = getFields() // your own methods
    this.props.untouch(fieldArray)
}

...

const mapStateToProps = (dispatch) => ({
    untouch: (fieldArray) => dispatch(untouch("YOUR_FORM_NAME", fieldArray))
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多