Forum OpenACS Development: Re: Res: Re: Res: Re: Res: Re: Res: Re: Res: Re: User Smart Search Widget with Ajax

Hi Lourdes,

What do you mean if I check my commit logs?

Posted by Lourdes Martínez on
Hi Eduardo, you mention previously that you don't remember how you did it, and you were going to review your commit logs and show me later.

I could not have resolved the problem yet. I only need to integrate the smart search widget (autosuggest) in a text box with the openacs doing only a select /n from a table.

Thanks for your help.

Posted by Ryan Gallimore on
Hi Lourdes,

Is it possible for you to upgrade your instance to version 5.4.3?

This is going back a ways, but I think the widget was developed without template::head.

If not, please post your code to so we can take a look.


Posted by Lourdes Martínez on
Ok, I will update my instance to the version 5.4.3. I don't know if that version have the ajaxhelper package.

I only need that the box show me the results of my select depending on the letter I write.

I show you my tree files:

1. smart-search-widget.tcl
set js_update_user_select [ah::ajaxupdate \
-container "results_box" \
-url "search-users" \
-pars "Form.serialize('searchform')"]

2. smart_search_widget.adp

<.. id="searchform">
<table border="0" cellpadding="0" cellspacing="0">
<.. type="text" name="search" id="search" onKeyUp="@js_update_user_select;noquote@ document.getElementById('results_box').style.visibility='visible';" autocomplete="off" value="" />

3. search_users.tcl
ad_page_contract {

@author Ryan Gallimore (
@creation-date 2006-09-23

} {
{search ""}

#ns_log notice "private-messaging search='$search'"

if { [string length $search] == 0 } {
ns_write "No results"
} elseif { [string length $search] < 3 } {
# Show all results if search string is 1 or two characters.
set search ""

set search [string tolower $search]
set package_id [ad_conn subsite_id]
set response ""

# Get users in the current subsite only

db_foreach get_search_results "

select n,n,n
from my_table
order by n

# select distinct u.username,
# p.first_names || ' ' || p.last_name as name,
# u.username as email
# from pers p, use u, acs_rels rel, app_groups ag
# where p.person_id = u.user_id
# and u.user_id = rel.object_id_two
# and rel.object_id_one = ag.group_id
# and ag.package_id = :package_id
# and (lower(p.first_names || ' ' || p.last_name) like '%$search%'
# or lower(u.username) like '%$search%')
# order by name

" {

set one_result "$name ($email)"

# Bold search text as you type
set start [string first $search [string tolower $one_result]]
set end [expr $start + [string length $search]]
set one_result_bolded "[string range $one_result 0 [expr $start-1]]&lt;b&gt;[string range $one_result [expr $start] $end][string range $one_result [expr $end+1] [expr [string length $one_result] - 1]]"

append response "&lt;a href=\"#\"&gt;$one_result_bolded&lt;/a&gt;&lt;br&gt;"

} if_no_rows {
set response "No results"

ns_write $response


Hi Eduardo / Hi Ryan:

Finally I could run the smart-search-widget!!! doing the upgrade and install the ajaxhelper package. Thankssss!

Now I need another help: when I write any letter in the box, the result bring me all the word that exist in the table.

I only need that the box go recognizing letter by letter and do a filter, and when I select my choice, this return into the box..

I'm not sure what .js file do this function?

Thanks again.

Hi Eduardo / Ryan:

I found the way to return exactly the letters I write...

How I do to select my choice and return this value into the box?

Hi Lourdes,

I'm glad you got the widget working with ajaxhelper.

Just click on the link and that will select the user and send you to another page.

If you want to change the link, look for it in user.tcl

For different behaviour, read through the ajaxhelper docs and see if you can find what you're looking for there.