following the steps on the wiki, drop down works but selected item
does not appear in text box (issue #1)
i am searching only on fname but the drop down actually shows the full
name by joining fname + " " + lname
i would also like it to return the user_id which is what i really need
to save in the db.
why is the selected answer not showing up and how i can get the id as
well
def auto_complete_for_user_fname
auto_complete_responder_for_member params[:user][:fname]
end
def auto_complete_responder_for_member(value)
@members = User.find......
render :partial => 'member_search'
end
the simple auto complete works in regards to name appearing in text
field, but not the customized. i thought this might be a css issue,
but i have ruled that out as well.
# view
Just a little test:
<%= text_field_with_auto_complete :user, :lname %>
no, that's not the issue -- autocomplete off just tells the browser not
to try to autocomplete the form
nothing's appearing because you don't have any data. make sure your
database query works and it's populating the partial correctly. your ul
class should be <ul class="members"> with each li being <li
class="member">[name here]</li> or something similar to that format.
also you should probably make sure you have skip_before_filter
:verify_authenticity_token, :only=>:auto_complete_for_user_id or whatnot
there as well
there was data, because the drop down was working, it was just not
selecting the name.
not sure if anyone else has come across this. i was comparing the the
two auto completes in firfox
with firebug and i noticed in the simple auto complete post response
from ajax was coming back all compacted (no spaces).
the complicated auto_response had all the correct information but
there were a lot of spaces.
so i deleted all the tabs and spacing from the partial, and it fixed
the problem. i also
noticed <%=h which i haven't come across before.
so that issue #1
i really need help with issue #2
i get the full name in the field, but i also want to get the id, even
in another field. i would really appreciate
a solution here. thanks. if i am not explaining my self please ask and
i will repost.
never got it to work, i will look into later. it would be great if
someone has small form code with this method, so i can look at it.
it's the easiest way to learn it but there is nothing out there, i
have searched hi and low.
i don't have a form. i first created the auto complete with a text
field, and looked at the code in firefox/firebug so i could understand
it. the form i want to create is simple.
user table
id
fname
lname
show all the users in the auto complete text field by full name. when
a user click on a name, i want to get user_id field, either by ajax or
with a submit button or with on enter.
Besides the docs themselves, you have working examples in
app/views/books/index.html.erb
not sure on what you mean here?
thanks for taking the time.
Hmmm, if there's no form to submit and no parent model let me suggest something that may be simpler: use Rails auto_complete plugin and put the user IDs as ids of the list items in the HTML completion list you send back.
<li id="<%= user.id %>"><%=h user.name %></li>
Then, in the text_field_with_auto_complete helper call configure a JavaScript callback in :after_update_element that extracts the ID of the selected user and does whatever needed with it:
function(element, value) {
var model_id = value.id;
...
}
That's the basic technique under model_auto_completer, only it automates some additional stuff that you may not need for that simple use case.