Forum: Ruby on Rails how to realize this behaviour

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
2e6d9ef543fde8e1f3fedc97d0b784a7?d=identicon&s=25 Stefan kilp (Guest)
on 2005-12-05 02:42

i am just doing my first steps with autocompleter and php.

i want to know if it is possible to build the following behaviour:

i have a small test app with one textinput

<form action=demo2_result.php>
Kontakt <input type="text" name=qwe id="autocomplete" size=20 on/>
<div class="auto_complete" id="autocomplete_choices"></div>
<script>  new Ajax.Autocompleter("autocomplete", "autocomplete_choices",
"server.php", {paramName: "qwe", minChars: 2});

the first problem the comes to me is, that there my be some entries
having the same caption (2 and 4) but different id in database.

--- db ------
id, caption
1, hans
2, peter
3, paul
4, peter

so i would need a structure for autocomplete to retrieve database id and
a caption.

next problem then is where to store database id.

this could be done with ie a hidden field, but the how would the
database id of the selected element be stored in the hidden field.

i need the database id instead of the caption for storing in the
database, as i want to use my autocomplete field as a replacement for a
db lookup field.

next problem:

if the user enters a text in the input field and hits tab right behind,
then no lookup is done. how can i force lookup then.

the basic idea is this:

1.) user enters text in a autocomplete field
2.) if he leaves the field (ab or mouse click) a lookup has to be done
3.) if he has entered "han" then there is only one hit "hans", so no
lookuplist is nessesary, text has only to be completed and record id
needs to be stored in form
4.) if he has entered "pe" then more then one record hits the search (2
and 4), so the lookuplist should appear to select the required item
5.) if no entry was found i would like to go to a create dialog to let
the user enter the missing lookup item

any hints welcome

This topic is locked and can not be replied to.