admin管理员组文章数量:1279051
Backbone.js es with model validation events, and I'm looking to integrate it with a lite validation framework.
I just started looking at /
any other remendations?
Backbone.js es with model validation events, and I'm looking to integrate it with a lite validation framework.
I just started looking at http://happyjs./
any other remendations?
Share Improve this question asked May 31, 2011 at 18:23 Edward ChanEdward Chan 8031 gold badge10 silver badges7 bronze badges3 Answers
Reset to default 4jQuery Validate is my favorite its well documented and used by many
Try the Backbone.Validations plugin
There are some validations plugins for backbone but I don't like it, I ended up with this:
...
validate: (attrs) ->
helper = @validationHelper attrs
helper.check 'name', (v) -> "can't be blank" if _(v).isBlank()
helper.check 'version', (v) -> "can't be blank" if _(v).isBlank()
helper.check 'organization', (v) -> "can't be blank" if _(v).isBlank()
helper.errors()
...
And here's the helper:
_(Backbone.Model.prototype).extend
validationHelper: (attrs) ->
helper =
_errors: {}
check: (name, validator) ->
return unless attrs and (name of attrs)
msg = validator attrs[name]
(@_errors[name] ?= []).push msg if msg
@
errors: -> if _(@_errors).any() then @_errors else null
return helper
本文标签: Javascript Validation Framework for BackbonejsStack Overflow
版权声明:本文标题:Javascript Validation Framework for Backbone.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741269177a2368961.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论