使用 redux-form 6.0.1
我有一个包含 2 个字段的表单。一个是选择器,另一个是输入。
<Field name="toLanguage" component="select" normalize={normalizeLanguage}>
{languages.map(function(item) {
return <option key={item.id} value={item.name}>{item.display}</option>;
})}
</Field>
<Field name="toValue" component="input" type="text" placeholder="toLanguageString" />
我想根据选择字段的状态更改输入更改的内容。我在这里读到了如何做到这一点:https://github.com/erikras/redux-form/issues/442
因此,为了尝试一下,我继续手动发送更改
<button type="button" onClick={() => dispatch(change('TranslationDetail', 'toValue', 'foo')) }>dispatch</button>
这可行,但这是最不推荐的方法。 当我尝试使用规范化器时,遇到了错误“Uncaught ReferenceError:未定义更改”。我应该如何更改标准化器以根据选择器的状态更改字段的值?
const normalizeLanguage = (value, previousValue, dispatch) => {
if (!value) {
return value
}
console.log(value)
dispatch(change('TranslationDetail', 'toValue', value))
return value
}
export default normalizeLanguage
最佳答案
您可能缺少对 change
函数的引用。在您的进口申报中包含以下行:
import {change} from 'redux-form';
关于javascript - redux-form:如何在规范化器中调度更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39225505/