Jump to content

Adding function autocomplete to rails app


appleii717

Recommended Posts

I

I found your autocomplete function and it is about as simple and complete than I've seen

I tried to installed it in the rails asset pipe line. I did convert it to coffee script, but I had to hack it get it running on a test page

Just adding at the end of the page were I was going to test it didn't work. 

    autocomplete(document.getElementById("myInput"), countries);

It ruturned couldn't find autocomple

The hack was to put autocomplete in the pipeline under jquery
    jQuery ->

      $("#startem").on "load", ->
        inp = document.getElementById("myInput")
        autocomplete(inp,entries)


      autocomplete = (inp, arr) -> .....

Then put on the test page

    #startem
    javascript:
      $(function() {
        $('#startem').trigger('load');
      });

The hack works, but I'm sure there is a better way. My Javascript knowledge if not that great.

Since it looks fairly reusable (I may have a few places I'd like to use it) I'm looking for suggestions on a corrent way.

Steve

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...