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

fix(Field): fix the issue of checking empty value #7050

Merged
merged 4 commits into from Sep 2, 2020

Conversation

beizhedenglong
Copy link
Contributor

@beizhedenglong beizhedenglong commented Aug 26, 2020

Some values like number 0, false shouldn't be treated as empty value.

@beizhedenglong
Copy link
Contributor Author

beizhedenglong commented Aug 26, 2020

像 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 });
});

@chenjiahan
Copy link
Member

其他 UI 组件库是按照哪一种标准来的嘞?

@beizhedenglong
Copy link
Contributor Author

beizhedenglong commented Aug 27, 2020

其他的主流组件库一般都不会有这种设定的。感觉不太合理, 像0,false 不应该认为是空值,不知道对你们是不是故意为之,这个改动对你们有影响吗

@chenjiahan
Copy link
Member

chenjiahan commented Aug 30, 2020

按照浏览器的原生行为,Checkbox 如果设置了 required,是必须要选中的。

如果不需要校验 Checkbox/Switch 的选中状态,可以不设置 required

@beizhedenglong
Copy link
Contributor Author

这个地方数字0也是有问题的,比如 RadioGroup 有三个数字选项0,1,2,设了必填,0现在是选不了的,只能特殊处理

@chenjiahan
Copy link
Member

数字 0 可以修复一下,没问题

@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2020

Codecov Report

Merging #7050 into dev will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/field/index.js 99.47% <100.00%> (+<0.01%) ⬆️
src/tabs/index.js 81.08% <0.00%> (-1.42%) ⬇️
src/action-sheet/index.tsx 100.00% <0.00%> (ø)
src/utils/interceptor.ts 100.00% <0.00%> (ø)
src/tabbar/index.js 94.11% <0.00%> (+0.36%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d97f7f6...5d2a1ae. Read the comment docs.

@chenjiahan chenjiahan merged commit f8d2572 into youzan:dev Sep 2, 2020
@chenjiahan
Copy link
Member

👍👍 辛苦

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

Successfully merging this pull request may close these issues.

None yet

3 participants