Take the 2-minute tour ×

What is the best way to use jQuery plugins like datepicker, chosen, etc in batman.js? I found data-mixin helper, but there is no documentation and examples with about how to use it. Also I found this issue: https://github.com/Shopify/batman/issues/199, but again I can't get it work, because it also undocumented.

Ideally I want to do something like this:

datePicker: (field) ->

<input data-helper="datePicker" ... >
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

I haven't used them yet. However, I think you should be able to use the "Really after afterFilters" afterFilters. Which are the afterFilers, but they've recently been revamped so they'll fire after the DOM has been rendered.

And by looking at the tests you should be able to specify them for an action. This should apply you to be DRY and only have the code in an afterFilter for specific actions.

test 'afterFilters on outer actions should fire after afterFilters on inner actions', 1, ->
  order = []
  class TestController extends Batman.Controller
    @afterFilter 'show', -> order.push 1
    @afterFilter 'test', -> order.push 2
    show: -> @render false
    test: ->
      @render false
      @executeAction 'show'

  @controller = new TestController
  @controller.dispatch 'test'
  deepEqual order, [1, 2]
share|improve this answer
Thanks! I've tried afterFilter before without success, but It seems that desired behavior appeared in master branch. Can I wait for a bit before accepting your answer? Maybe there's an easier solution with mixins... Thank you again. –  Mikhail D Jul 2 '12 at 7:56
Np. If you figure out a way to do it with mixins let me know :) –  RyanonRails Jul 2 '12 at 15:46
add comment

In the end I came to that: calling plugins in the end of particular action. For example:

#controllers action
new: (params) ->
  #some logic here
  @view = @render()
  @view.on 'ready', =>

Taken from: https://groups.google.com/forum/?fromgroups#!topic/batmanjs/dkYg7ijpaQI

But it doesn't looks like DRY solution. I'm still looking for something more optimal.

share|improve this answer
add comment

Your Answer


