Jquery Validate with Coffeescript
Jquery Validate with Coffeescript
所以我可以在javascript 中使用以下代码
validateSearchForm:=>
$(@el).find("#form").validate({
rules:{
startDateInputBox:{
dateISO:true,
endDateInputBox:{lessThan : "#licenseStart"}
},
endDateInputBox:{
dateISO:true
}
searchPurposeBox:"required"
}
});
$.validator.addMethod "lessThan",(value,element)->
//do some stuff
,"some comment"
但lessThan函数在coffee中一直没有定义。很确定这是语法错误-有人能帮忙吗?
我不确定它是否能解决您的问题,但请尝试在没有{}
:的情况下定义您的对象
rules:
startDateInputBox:
dateISO: true,
endDateInputBox:
lessThan: "#licenseStart"
endDateInputBox:
dateISO: true
searchPurposeBox: "required"
您的代码结构如下:
validateSearchForm: =>
$(@el).find('#form').validate({ ... })
$.validator.addMethod "lessThan", (value, element) ->
#...
, "some comment"
因此,您在尝试验证表单之后调用$.validator.addMethod
。您应该在尝试使用它们之前添加所有额外的验证方法,并且可能应该在验证表单的方法之外添加它们。更像这样的东西:
# Somewhere in your global application set up...
$.validator.addMethod "lessThan", (value, element) ->
#...
, "some comment"
# And then elsewhere...
class Whatever
#...
validateSearchForm: =>
$(@el).find('#form').validate({ ... })
您必须非常注意CoffeeScript中的缩进,缩进提供了代码结构的一半,因此它必须是正确的,并且应该是一致的。
相关文章:
- Fighting with FRP
- issue with FB.Event.subscribe
- geolocation-marker.js conflict with markerclusterer.js
- Angular 2.0 with JavaScript or TypeScript?
- 为什么不推荐使用“with”?是否有更好或其他方法可以“下降”到对象的命名空间
- WebComponentsJS with IE10
- 指令的模板必须只有一个根元素:With restrict E&替换true
- timeago.js with datatable and PHP
- Ajax and Json with Rails
- errors with Javascript try catch
- how to split a string with ','
- Understanding Javascript scope with "var that = this&qu
- Architecture for CPU intensive tasks with NodeJS & Socke
- How to declare a Map containing certain properties with flow
- 设置'这'在React with Inverse Data Flow中
- Unit-testing multiple use cases with Karma & Mocha.js
- Jquery Validate with Coffeescript
- Coffeescript Promise with Jquery Post
- preventDefault在使用CoffeeScript with Rails4提交时未处理else条件
- .bind function with CoffeeScript