使用Joi在React.js中逐个验证字段。

huangapple go评论119阅读模式
英文:

Validating fields one by one using Joi in React.js

问题

Joi 中,可以定义模式,然后将字段对象传递以验证它们。但有时因为用户体验要求,我们需要在失焦时逐个验证字段,同时在最后将它们全部一起验证。

Joi 中是否有一种标准方法可以同时实现这两种验证方式?(例如,是否有一种方法可以从模式中提取一个验证器并将其应用于特定字段)。

如果您知道更好的软件包或方法,请分享。

英文:

As you might know, we can define schema in Joi and then pass the fields object to validate all of them. but some times because of UX requirements, we need to validate fields one by one onBlur AND also at the end, validating them all together.

Is there any standard way in Joi to have both in place? (e.g. any method to extract one validator from the schema and apply it to a specific field).

Also if you know any better package or approach for this, please share.

答案1

得分: 0

看起来 Joi 有一个名为 extract() 的方法,用于提取一个键并仅基于该键进行验证。

https://joi.dev/api/?v=17.8.3#anyextractpath

英文:

Seems Joi has a method called extract() to extract a key and validate only based on that.

https://joi.dev/api/?v=17.8.3#anyextractpath

huangapple
  • 本文由 发表于 2023年3月8日 19:15:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75672306.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定