Batman.js is no longer in production at Shopify and is not actively maintained.

This website is left for reference (and for old times' sake).


Batman.ValidationErrors represent a failure for a record's field to to pass validation. They are usually accessed by getting a record's errors.

  • constructor(attribute: String, messageOrKey: String, options={}) : ValidationError

    Returns a new validation error for attribute. messageOrKey and options are used to create the error message:

    • if options.message is a string, it is used as the error's message
    • if options.message is a function, it is called on the record with (attribute, messageKey)
    • if messageOrKey is underscore-cased, it is used to lookup an error message
    • otherwise, messageOrKey is used as the error's message

    options.interpolations is interpolated into error message if one is found for messageOrKey.

  • fullMessage : String

    Returns the human-readable attribute name and the validation message:

    test "ValidationError should humanize attribute in the full message", ->
      class Product extends Batman.Model
      product = new Product
      error = new Batman.ValidationError("fooBarBaz", "isn't valid")
      equal error.get('fullMessage'), "Foo bar baz isn't valid"

Help us improve our documentation!

Contributions to this page are welcome on Github. If you find a problem but you cannot fix it, please open an issue.

Discussion regarding batman.js documentation is also welcome on our mailing list.