2
我想在Redux-Form中一次更改表單的兩個字段值。 存在更改方法,但它只允許更改一個字段。 請問有什麼方法可以一次更改一個字段值?Redux-form:一次更新/更改兩個字段值
Ex。
Fields:
- patternType
- color
我想同時設置這兩個字段。
我想在Redux-Form中一次更改表單的兩個字段值。 存在更改方法,但它只允許更改一個字段。 請問有什麼方法可以一次更改一個字段值?Redux-form:一次更新/更改兩個字段值
Ex。
Fields:
- patternType
- color
我想同時設置這兩個字段。
不知道是否有一個更好的辦法,但如果你希望兩個變化的兩個輸入值的基礎上,只有一個變化這樣工作的:
const Form = ({change, dispatch}) => {
const onFirstChange = (event) => {
const text = event.target.value;
// make change actions for both inputs
const changeFirst = change('first', text);
const changeSecond = change('second', text + text.toUpperCase());
// dispatch them for both
dispatch(changeFirst);
dispatch(changeSecond);
};
return (<div>
First: <Field name='first' component='input' type='text' onChange={onFirstChange} /><br />
Second: <Field name='second' component='input' type='text' />
</div>
)
};
const MyForm = reduxForm({
form: 'foo'
})(Form);
// END EXAMPLE
ReactDOM.render(
<Provider store={store}>
<MyForm />
</Provider>,
document.getElementById('root')
);
的jsfiddle演示:https://jsfiddle.net/jonahe/399cpnz1/1/
嘿!怎麼樣了?你自己找到了解決方案嗎?聽到我的回答是否有用,或者我誤解了你的問題,我會很高興。 – jonahe