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
fix(Field): fix the issue of checking empty value #7050
Conversation
像 switch 这种组件设置了必选,就变成了只能选true,感觉不太合理,你们很依赖这个特性嘛? test('use switch', async () => {
const { wrapper, onSubmit, onFailed } = mountFormWithChild({
template: '<van-switch v-model="value" />',
data() {
return { value: false };
},
});
await submitForm(wrapper);
expect(onFailed).toHaveBeenCalledWith({
errors: [{ message: 'foo', name: 'A' }],
values: { A: false },
});
wrapper.setData({ value: true });
await submitForm(wrapper);
expect(onSubmit).toHaveBeenCalledWith({ A: true });
}); |
其他 UI 组件库是按照哪一种标准来的嘞? |
其他的主流组件库一般都不会有这种设定的。感觉不太合理, 像0,false 不应该认为是空值,不知道对你们是不是故意为之,这个改动对你们有影响吗 |
按照浏览器的原生行为,Checkbox 如果设置了 required,是必须要选中的。 如果不需要校验 Checkbox/Switch 的选中状态,可以不设置 required |
这个地方数字0也是有问题的,比如 RadioGroup 有三个数字选项0,1,2,设了必填,0现在是选不了的,只能特殊处理 |
数字 0 可以修复一下,没问题 |
Codecov Report
@@ Coverage Diff @@
## dev #7050 +/- ##
==========================================
+ Coverage 91.26% 91.27% +0.01%
==========================================
Files 176 177 +1
Lines 4741 4747 +6
Branches 279 284 +5
==========================================
+ Hits 4327 4333 +6
Misses 378 378
Partials 36 36
Continue to review full report at Codecov.
|
👍👍 辛苦 |
Some values like number
0
,false
shouldn't be treated as empty value.