1

I have the following (simple) CoffeeScript jQuery Plugin:

$ = jQuery

$.fn.extend
    schoolSelect: (options) ->
        settings = 
            apiUrl: '/api/v1'
            debug: false

        settings = $.extend settings, options

        log  = (msg) ->
            console?.log msg if settings.debug

        return @each ->
            @.dropkick
                change: (val, label) ->
                    log val
                    log label

And I call it in another CoffeeScript file like so:

$('.school_select').schoolSelect
        debug: true

But for some reason I keep getting the following error: Uncaught TypeError: Object #<HTMLSelectElement> has no method 'dropkick'

I am using the DropKickjQuery plugin for my HTML selects: http://jamielottering.github.com/DropKick/

How can I access the DropKick plugin within my CoffeeScript jQuery plugin?

1 Answer 1

2

This line:

    return @each ->
        @.dropkick

Needs to be

    return @each ->
        $(@).dropkick

In the context of a jQuery callback for each, this gives you back a raw DOM element (hence the warning about HTMLSelectElement), not a jQuery object.

If your plugin is calling another plugin, you need to ensure the setup for the DropKick plugin is done before you extend jQuery.

Sign up to request clarification or add additional context in comments.

1 Comment

I knew it was something simple! Thanks for the help! It works like a charm now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.