【发布时间】:2020-08-18 15:41:27
【问题描述】:
我想在打开表单时选中“精确”单选按钮:
<Form
onSubmit={onSubmit}
initialValues={{ match_type: "exact" }}
render={({ handleSubmit, form, reset, submitting, pristine, values }) => (
<form
onSubmit={() => {
handleSubmit();
}}
>
<fieldset>
<legend>Match type</legend>
<Field name="match_type">
{({ input }) => (
<label>
<input {...input} type="radio" value="fuzzy" /> Fuzzy
</label>
)}
</Field>
<Field name="match_type">
{({ input }) => (
<label>
<input {...input} type="radio" value="exact" /> Exact
</label>
)}
</Field>
</fieldset>
<button type="submit">Save match</button>
</form>
)}
/>
单选按钮保持未选中状态。知道我应该如何让它工作吗?注意使用<Field component="input" type="radio" .../> 对我来说不是一个选项。
代码沙盒:https://codesandbox.io/s/react-final-form-reset-after-submit-forked-q6jyv?file=/index.js:359-1235
【问题讨论】:
-
尝试对指定输入使用 defaultChecked={true}
-
或者checked属性怎么样
-
这两种方法都不会为最终表单的状态提供值。
标签: reactjs react-final-form final-form