英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论