assets/scripts/coffee/hoarder/validator/constraints/min_length_constraint.coffee in hoarder-js-0.0.1 vs assets/scripts/coffee/hoarder/validator/constraints/min_length_constraint.coffee in hoarder-js-0.0.2
- old
+ new
@@ -1,18 +1,12 @@
-ValidationError = require "hoarder/validator/error/validation_error"
+BaseConstraint = require "hoarder/validator/constraints/base_constraint"
-#
-# @author - Tim Shelburne <tim@musiconelive.com>
-#
-#
-#
-class MinLengthConstraint
- canHandle: (type)->
- type is "minLength"
+class MinLengthConstraint extends BaseConstraint
+
+ constructor: ->
+ @type = "minLength"
- handle: (element, context)->
- if element.value.length >= context.value
- return []
- else
- return [ new ValidationError "The minimum length of this field is #{context.value}." ]
+ rulePasses: (element, rule)-> element.value.length >= rule.context
+
+ errorMessage: (rule)-> "The minimum length of this field is #{rule.context}."
return MinLengthConstraint
\ No newline at end of file