crowdint / rails3-jquery-autocomplete

An easy and unobtrusive way to use jQuery's autocomplete with Rails 3

Home Page:http://rubygems.org/gems/rails3-jquery-autocomplete

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JavaScript error using the :update_elements option

donv opened this issue · comments

Hi!

Thanks for a very useful gem!

I am trying to use the :update_elements option, but I am getting an error.

When I try the example given in the README like

:update_elements => {:id => '#id_element', ...}

I get a JavaScript error like this

TypeError: 'null' is not an object (evaluating 'ui.item.id.toString')

The stack trace indicates that the error occurs in autocomplete-rails.js line 90

var data = jQuery(this).data(ui.item.id.toString());

Am I doing something wrong?

I found the error. I was not using the "id" field to update any element, and I did not send it in the xhr response. It seems the "id" field is required even if it is not used to update any element.

Sending the "id" field in the xhr response solved the problem.