List Info

Thread: Ajax.Autocompleter with a twist




Ajax.Autocompleter with a twist
user name
2006-08-14 00:53:23
Hello all,

I'm hoping to use the Ajax.Autocompleter to help users send
private
messages to other users on my site. As the user types in the
name of
another user, Ajax.Autocompleter steps in and offers a few
relevant
options to help them along. Once they find the right one,
Scriptaculous makes it a breeze for them to select it and
enter it
into the input field.

I'd like to take this one more step, however, and make note
of the
user id (the primary key associated with the name they
selected from
the database) as an invisible field or javascript variable.
With this,
it would be simple to send the private message to the
appropriate user
id. The problem is that since the backend side of
Ajax.Autocompleter
returns an unordered list, I don't know how/ where to store
the id
numbers, or how the form could track that somehow.

All help is welcome. Thanks everyone!
-Colin
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffslists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-
spinoffs
Ajax.Autocompleter with a twist
user name
2006-08-14 14:02:29

Colin Angevine wrote:
> Hello all,
> 
> I'm hoping to use the Ajax.Autocompleter to help users
send private
> messages to other users on my site. As the user types
in the name of
> another user, Ajax.Autocompleter steps in and offers a
few relevant
> options to help them along. Once they find the right
one,
> Scriptaculous makes it a breeze for them to select it
and enter it
> into the input field.
> 
> I'd like to take this one more step, however, and make
note of the
> user id (the primary key associated with the name they
selected from
> the database) as an invisible field or javascript
variable. With this,
> it would be simple to send the private message to the
appropriate user
> id. The problem is that since the backend side of
Ajax.Autocompleter
> returns an unordered list, I don't know how/ where to
store the id
> numbers, or how the form could track that somehow.

There's a couple ways to do this. The auto completer values
are an un-ordered
list, but they can have other stuff in there. You are
allowed to have a tag of
class "informal" that is displayed, but not used
as a value. So do something
like this

<ul>
  <li>
    <span class="id"
style="display:none">1234</span>
    <span class="informal">John Doe
(jdoecompany.org)</span>
  </li>
</ul>

See http://demo.script.aculo.us/ajax/autocompleter_customiz
ed for more details
and an example.

-- 
Michael Peters
Developer
Plus Three, LP

_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffslists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-
spinoffs
Ajax.Autocompleter with a twist
user name
2006-08-14 22:33:28
I took a look at the example on the Scriptaculous site and
I'm still a
bit unclear. I'm already using the informal class, and it
makes good
sense to use it again (with a display:none there) but I'm
not sure how
I'll be able to retrieve that id number once the user
selects it. Just
a bit more context around how you approached it (or maybe a
peek at
the code you put together) would be wonderful.

Thanks,
Colin

On 8/14/06, Michael Peters <mpetersplusthree.com> wrote:
>
>
> Colin Angevine wrote:
> > Hello all,
> >
> > I'm hoping to use the Ajax.Autocompleter to help
users send private
> > messages to other users on my site. As the user
types in the name of
> > another user, Ajax.Autocompleter steps in and
offers a few relevant
> > options to help them along. Once they find the
right one,
> > Scriptaculous makes it a breeze for them to select
it and enter it
> > into the input field.
> >
> > I'd like to take this one more step, however, and
make note of the
> > user id (the primary key associated with the name
they selected from
> > the database) as an invisible field or javascript
variable. With this,
> > it would be simple to send the private message to
the appropriate user
> > id. The problem is that since the backend side of
Ajax.Autocompleter
> > returns an unordered list, I don't know how/
where to store the id
> > numbers, or how the form could track that somehow.
>
> There's a couple ways to do this. The auto completer
values are an un-ordered
> list, but they can have other stuff in there. You are
allowed to have a tag of
> class "informal" that is displayed, but not
used as a value. So do something
> like this
>
> <ul>
>   <li>
>     <span class="id"
style="display:none">1234</span>
>     <span class="informal">John Doe
(jdoecompany.org)</span>
>   </li>
> </ul>
>
> See http://demo.script.aculo.us/ajax/autocompleter_customiz
ed for more details
> and an example.
>
> --
> Michael Peters
> Developer
> Plus Three, LP
>
> _______________________________________________
> Rails-spinoffs mailing list
> Rails-spinoffslists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-
spinoffs
>
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffslists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-
spinoffs
Ajax.Autocompleter with a twist
user name
2006-08-15 00:29:16
On Mon, Aug 14, 2006 at 06:33:28PM -0400, Colin Angevine
wrote:
> I took a look at the example on the Scriptaculous site
and I'm still a
> bit unclear. I'm already using the informal class, and
it makes good
> sense to use it again (with a display:none there) but
I'm not sure how
> I'll be able to retrieve that id number once the user
selects it. Just
> a bit more context around how you approached it (or
maybe a peek at
> the code you put together) would be wonderful.

You must use a callback (with updateElement option to
Ajax.Autocompleter) and that callback does something like
id =
chosen_option.getElementsByTagName("span")[0].in
nerHTML;
then you can use the id as you like.

Previously discussed on the list:
http://lists.rubyonrails.org/pipermai
l/rails-spinoffs/2006-July/004864.html

Saludos,
					HoraPe
---
Horacio J. Peņa
horapecompendium.com.ar
horapeuninet.edu
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffslists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-
spinoffs
[1-4]

about | contact  Other archives ( Real Estate discussion Medical topics )