-
Notifications
You must be signed in to change notification settings - Fork 7.8k
feat: 保存表单字段的blur状态 #5686
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
feat: 保存表单字段的blur状态 #5686
Conversation
|
WalkthroughThe changes add new functionality for managing form field blur states. A private property and two methods have been introduced to the form API to track and update the blur state of fields. The form field component is updated to trigger these methods on blur and focus events. The form context is extended with an additional type, and the provided form properties now include the form API. Overall, these modifications improve how user focus interactions are tracked and incorporated into form validation. Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant FFC as Form Field Component
participant FA as FormApi
U->>FFC: Triggers onBlur event
FFC->>FA: setFieldBlurState(fieldName, true)
Note right of FA: Field blur state is set to true
U->>FFC: Triggers onFocus event
FFC->>FA: setFieldBlurState(fieldName, false)
Note right of FA: Field blur state is reset to false
sequenceDiagram
participant Comp as vben Use Form Component
participant PF as provideFormProps
participant Context as FormContext
Comp->>PF: Call provideFormProps([forward, form, formApi])
PF->>Context: Provides context with extended form API
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
⏰ Context from checks skipped due to timeout of 90000ms (2)
🔇 Additional comments (11)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
#5689 提供了新的表单api方法,无需额外保存blur状态 |
Description
目前表单验证有一个问题,在自定义验证的时候校验方法会被多次调用( #5437),vee-validate的作者表示这是正常的(logaretm/vee-validate#4737),修改值的时候虽然不会显示错误信息,但是会调用校验方法。如果需要异步校验,这样会多次发送请求很浪费资源。
我通过组件的blur事件保存当前字段的blur状态到
formApi
中,这样自定义校验的时候通过formApi.getFieldBlurState
可以拿到当前字段的blur状态,根据这个状态判断要不要发送请求校验数据,避免了多次请求的麻烦。示例
使用
validateOnModelUpdate: false
和validateOnBlur: true
才能保存字段的blur状态,只有input可以保存,其他类型的字段设置没用const blurState = formApi.getFieldBlurState(fieldName);
获取字段的blur状态,如果字段已经blur会返回true
Type of change
Please delete options that are not relevant.
pnpm-lock.yaml
unless you introduce a new test example.Checklist
pnpm run docs:dev
command.pnpm test
.feat:
,fix:
,perf:
,docs:
, orchore:
.Summary by CodeRabbit
New Features
Refactor