I've recently added Breeze to a project using Knockout and ASP.NET MVC4. I really like Breeze and it saves a lot of coding.
I have used Knockout validation and like how it validates a property field text box on data entry and the way the error message is displayed.
I would like to use a combination where the validation requirements are defined in the back-end with C# attributes on the object properties, the validation requirements are received in the metadata and then Knockout validation can be used.
I think I can work around it by defining the properties in the front end and applying Knockout validation eg
classProperty.extend({ required: true }) .extend({ minLength: 3 });
Is there a way to use Knockout validation without having to apply the validation requirements in the front-end? If not, are you considering doing this?
这个问题是由 johnvarney 在我们的 IdeaBlade 论坛上发布的。我在这里重新发布问题和答案,因为我认为它对 Breeze Stack Overflow 社区有用。
最佳答案
您可能已经注意到,Breeze 已经基于元数据执行验证。基本的“验证”规则,例如是否需要一个属性、它的数据类型以及它的长度(如果字符串在服务器上自动生成并发送到客户端)。这些验证规则也可以通过直接修改客户端上的“验证”元数据来扩展。
API 文档中提供了有关此主题的更多信息:http://www.breezejs.com/sites/all/apidocs/classes/Validator.html以及在 Breeze Samples 下载中的“DocCode”示例目录中。
我们还计划提供有关如何将 Breeze 验证“连接”到各种第三方库(例如 jQuery 和 Knockout)的示例。不幸的是,这些示例目前不是高优先级,因为需要处理其他高度要求的功能。您可能希望通过我们的 Breeze User Voice https://breezejs.uservoice.com/forums/173093-breeze-feature-suggestions 为这些示例的工作投票。 .在决定下一步做什么时,我们会认真对待该地点。
关于knockout.js - Breeze 和 Knockout 中的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13616621/