Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当Field.Checkbox为multiple状态的时候 里面这段代码会报错 0.3.20版本 #56

Open
zl612 opened this issue Mar 29, 2024 · 11 comments

Comments

@zl612
Copy link

zl612 commented Mar 29, 2024

image
image

const selected = multiple
? (value as T[]).indexOf(checkboxValue) > -1
: value === checkboxValue

@zl612
Copy link
Author

zl612 commented Mar 29, 2024

另外单选和多选 组件为什么没有分开呢 这样用户使用习惯不一致

@onlyling
Copy link
Contributor

const selected = multiple
  ? (value as T[]).indexOf(checkboxValue) > -1
    : value === checkboxValue

这里报错可能是你给的值是 null,或者非数组的值导致的。

@onlyling
Copy link
Contributor

另外单选和多选 组件为什么没有分开呢 这样用户使用习惯不一致

这个问题暂时没有比较好的答案,许多组件都是多选、单选两个模式都可以使用。
这个设计的目的是可以在单选、多选之间快速切换,实现的过程中不用写两份相似的组件。

@zl612
Copy link
Author

zl612 commented Mar 29, 2024

const selected = multiple
  ? (value as T[]).indexOf(checkboxValue) > -1
    : value === checkboxValue

The error here may be caused by the value you gave is null, or the value is not an array.

I didn't pass a value 做的是一个非受控组件

@onlyling
Copy link
Contributor

onlyling commented Apr 1, 2024

const selected = multiple
  ? (value as T[]).indexOf(checkboxValue) > -1
    : value === checkboxValue

The error here may be caused by the value you gave is null, or the value is not an array.

I didn't pass a value 做的是一个非受控组件

src/checkbox/__fixtures__/group.tsxsrc/field/__fixtures__/checkbox.tsx
这两个案例都没有复现你说的报错,feat-expo 分支使用模拟器测试,main 分支在文档(web端)测试。

const options = new Array(6).fill(0).map((_, index) => ({
  value: index + 1,
  label: `选项${index + 1}`,
}))

const Demo = () => {
  return <>
    <Checkbox.Group options={options} />
    <Field.Checkbox title="多选:非受控" multiple options={options} />
  </>
}

@zl612
Copy link
Author

zl612 commented Apr 1, 2024

image
zhao找到问题所在了 如果form中initialValues没有赋值 或者声明就会报错

@zl612
Copy link
Author

zl612 commented Apr 1, 2024

真心建议把单选Radio和Checkbox分开 或者把Checkbox的圆形图标 多选的时候改成方形 这是用户使用习惯的问题 不然使用的时候还得告诉用户 这是可以多选的

@onlyling
Copy link
Contributor

onlyling commented Apr 1, 2024

真心建议把单选Radio和Checkbox分开 或者把Checkbox的圆形图标 多选的时候改成方形 这是用户使用习惯的问题 不然使用的时候还得告诉用户 这是可以多选的

可以在下个大版本区分出来,这个版本暂时这样。

@onlyling
Copy link
Contributor

onlyling commented Apr 1, 2024

image zhao找到问题所在了 如果form中initialValues没有赋值 或者声明就会报错

表单环境复现到报错,Field.Checkbox 在单选情况下渲染了页面,改成多选保存代码会提示错误。
image

@zl612
Copy link
Author

zl612 commented Apr 1, 2024

目前这个版本解决方案就是在initialValues中声明一下默认值 可以为空数组

@inkCrazy
Copy link

inkCrazy commented Feb 22, 2025

"@fruits-chain/react-native-xiaoshu": "^0.4.2",
我在封装自己的dataform的时候,表单编辑情况下,initialValues不可能设置为空数组,报错
Field.Checkbox的options设置空数组的时候也不会报错

Image
Image

报错:

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants