简体   繁体   中英

Rails jQuery autocomplete using coffescript

I am trying to get auto complete to work using the jquery UI, but it doesn't seem to be triggered.

The hashtag.js.coffee is being loaded into the application.js. There are no errors being thrown in the console either

hashtag.js.coffee

$('.swag_text_field').autocomplete
source: ['foo', 'food', 'four']

view

<%= form_tag hashtags_path, class: "search-form", remote: true do %>
            <div class="input-prepend input-append">
            <span class="add-on swag">#</span>

            <%= text_field_tag :hashtag, nil, class: "span4 swag_text_field", id:"appendedPrependedInput" %>

            <%= submit_tag "VS!", class: "btn add-on-right swag_button" %>
            <% end %>

Turns out coffee script is white space sensitive.

   jQuery ->
        $('.swag_text_field').autocomplete
            source: ['foo', 'food', 'four']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM