Auto_complete data and text field

two problems with auto_complete.

i have user table with
id
fname,
lname,

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

_member_search
simply loops through @members

thanks

You may want to look at this:
http://railscasts.com/episodes/102

yes, i looked at it and got even more confused because it was doing an
associate

On Apr 22, 5:39 pm, Andrew S. [email protected]

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 %>

controller

auto_complete_for :user, :name

view:
<%= text_field_with_auto_complete :user, :id %>

controller:

def auto_complete_for_user_id
@users = User.find(:all, :conditions => [ ‘LOWER(f_name) LIKE ?’,
‘%’+params[:user][:f_name]downcase+’%’ ], :order => ‘f_name asc’)
render :partial => ‘auto’
end

partial _auto.html.erb:

    <% for u in @users do -%>
  • <%=h u.id %> (<%=h u.f_name%>)
  • <% end -%>

this should get a drop down menu of first names that puts the id in the
text field

rushnosh wrote:

yes, i looked at it and got even more confused because it was doing an
associate

On Apr 22, 5:39�pm, Andrew S. [email protected]

nope, that one doesn’t even display a drop down.

sorry, params[:user][:f_name].downcase

here is my code from firefox. why does it say autocomplete off, is
this the issue?

Members

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

    with each li being
  • [name here]
  • 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

    rushnosh wrote:

    here is my code from firefox. why does it say autocomplete off, is
    this the issue?

    Members

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.

On Apr 23, 2008, at 1:16 , rushnosh wrote:

i would also like it to return the user_id which is what i really need
to save in the db.

Have a look at model_auto_completer:

http://agilewebdevelopment.com/plugins/model_auto_completer

– fxn

@xavier, i hope i can get this to work.
plugin is installed, server restarted.

i read thru your docs.here is the error

undefined method `text_field_with_model_auto_completer’ for
#ActionView::Base:0x230968c

<%= text_field_with_model_auto_completer :user, :fname, :id, :my_id %>

undefined method `reflect_on_association’ for NilClass:Class

i saw another example and tried but got the error above:

<%= belongs_to_auto_completer :user, :fname, :id %>
is this suppose to create the text field?

On Apr 23, 2008, at 13:40 , rushnosh wrote:

@xavier, i hope i can get this to work.
plugin is installed, server restarted.

i read thru your docs.here is the error

undefined method `text_field_with_model_auto_completer’ for
#ActionView::Base:0x230968c

<%= text_field_with_model_auto_completer :user, :fname, :id, :my_id %>

Hi, the plugin does not define such helper, note that the docs are here:

http://model-ac.rubyforge.org/classes/ModelAutoCompleterHelper.html

You normally use belongs_to_auto_completer.

– fxn

On Apr 23, 2008, at 13:59 , rushnosh wrote:

undefined method `reflect_on_association’ for NilClass:Class

i saw another example and tried but got the error above:

<%= belongs_to_auto_completer :user, :fname, :id %>
is this suppose to create the text field?

Does that text field live in a form about a different model? Some
model you dealing with that has a user_id?

– fxn

On Apr 23, 2008, at 20:17 , rushnosh wrote:

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.

Besides the docs themselves, you have working examples in

app/views/books/index.html.erb

checking out

svn://rubyforge.org/var/svn/model-ac/trunk

Does that text field live in a form about a different model? Some
model you dealing with that has a user_id?

Please, could you respond to that question?

– fxn

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.

On Apr 23, 2008, at 20:43 , rushnosh wrote:

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.

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.

– fxn

@xavier

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs