小编Chr*_*ast的帖子

React-hook-form:在选择元素中使用readyOnly

我尝试在选择元素中使用 readOnly,以便用户无法更改输入字段的值,但在提交表单时,我仍然需要 Api 的该值,而且我听说这是在 React-hook 中执行此操作的唯一方法-form 是使用只读而不是禁用,它在正常输入字段中工作,但打字稿在选择元素中给出错误。这是代码:

interface dataProps {
  field_id: any;
  disabled: boolean;
}
Run Code Online (Sandbox Code Playgroud)
<select
  readOnly={props.disabled}
  id={props.field_id}
  {...register(...)}
  defaultValue={...}
  onChange={...}
  >
  <option>
    {...}
  </option>
  renderList(...)
</select>
Run Code Online (Sandbox Code Playgroud)

我尝试尽可能缩短代码,这是我得到的整个错误:

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>'.
Run Code Online (Sandbox Code Playgroud)

我阅读了react-hook-form的文档,但我没有看到任何有关使用的内容readOnly,我登陆了这个链接,当我尝试更改必须选择的输入时,readOnly它给出了相同的错误,有没有办法使那readOnly行得通,还是有一个解决方法可以使禁用的数据保存在handleSubmit

html javascript forms reactjs react-hook-form

2
推荐指数
1
解决办法
8755
查看次数

如何在控制台中记录一个给定半径的圆?

我正在尝试使用我选择的符号在控制台中绘制一个圆圈,例如:'*',这是想要的结果:

drawCircle(5); //now I want to draw a circle with a radius of 5

    **
 *      *
*        *
 *       *
  *    *
    **
//this is a very ugly circle, but you probably get my idea.
Run Code Online (Sandbox Code Playgroud)

这是我迄今为止尝试过的:

const drawCirle = (radius) =>{
    const thickness = 0.4;
    const symbol = '*';
    const rin = radius - thickness
    const rout = radius + thickness;
    for(let y = radius; y >= -radius; --y){
        for(let x = -radius; x < rout; x += 0.5){ …
Run Code Online (Sandbox Code Playgroud)

javascript algorithm math

0
推荐指数
1
解决办法
55
查看次数

标签 统计

javascript ×2

algorithm ×1

forms ×1

html ×1

math ×1

react-hook-form ×1

reactjs ×1