Skip to content

fix(Form): fix date rule rejecting YYYY-MM-DD values - #4667

Open
kwy404 wants to merge 1 commit into
Tencent:developfrom
kwy404:fix/form-date-rule-delimiter
Open

kwy404 wants to merge 1 commit into
Tencent:developfrom
kwy404:fix/form-date-rule-delimiter

Conversation

@kwy404

@kwy404 kwy404 commented Oct 1, 2026

Copy link
Copy Markdown

这个 PR 的性质是?

  • 日常 bug 修复
  • 新特性提交
  • 文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • CI/CD 改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他

相关 Issue

No existing issue.

需求背景和解决方案

Root cause: isDate in common/validator.ts (the port of validator.js added in #4338) always splits the input by the delimiter found in format. validator.js only does that in strictMode; otherwise it splits the input by the first allowed delimiter the input contains. With the default options (format: 'YYYY/MM/DD', delimiters: ['/', '-']), a { date: true } rule therefore fails on 2024-01-31, although - is an allowed delimiter, validator.js accepts it, and the Form accepted it before #4338.

Fix: outside strictMode, split the input by the first allowed delimiter it contains, like validator.js does. strictMode still uses the format delimiter. uniapp-components/common/validator.ts has the same code and gets the same change.

Test: added form-item/__test__/form-model.test.js, which validates 2024/01/31 and 2024-01-31 with { date: true }. Before the fix the 2024-01-31 assertion fails (expected true, received false); after the fix it passes.

更新日志

  • 本条 PR 不需要纳入 Changelog

tdesign-miniprogram

  • fix(Form): fix date rule rejecting dates that use - as delimiter with the default options

@tdesign/uniapp

  • fix(Form): fix date rule rejecting dates that use - as delimiter with the default options

@tdesign/uniapp-chat

请求合并前的自查清单

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • Changelog 已提供或无须提供

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.

1 participant