我試圖在選擇元素中使用 readOnly 以便用戶無法更改輸入欄位的值但是在提交表單時我仍然需要 Api 的值,我聽說這是在 react-hook 中做到這一點的唯一方法-form 是使用 readOnly 而不是禁用,它在普通輸入欄位中作業,但打字稿在選擇元素中給出錯誤。這是代碼:
interface dataProps {
field_id: any;
disabled: boolean;
}
<select
readOnly={props.disabled}
id={props.field_id}
{...register(...)}
defaultValue={...}
onChange={...}
>
<option>
{...}
</option>
renderList(...)
</select>
我試圖盡可能地縮短代碼,這是我得到的整個錯誤:
Type '{ children: any[]; defaultValue: any; onChange: (e: ChangeEvent<HTMLSelectElement>) => void; onBlur: ChangeHandler; ref: RefCallBack; name: string; readOnly: true; id: any; }' is not assignable to type 'DetailedHTMLProps<SelectHTMLAttributes<HTMLSelectElement>, HTMLSelectElement>'.
Property 'readOnly' does not exist on type 'DetailedHTMLProps<SelectHTMLAttributes<HTMLSelectElement>, HTMLSelectElement>'.
我閱讀了 react-hook-form 的檔案,但我沒有看到任何關于 using 的內容readOnly,我登陸了
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/327205.html
標籤:javascript html 反应 形式 反应钩形
