autocompleter {select}

0 views
Skip to first unread message

Bobby Brown

unread,
Jul 20, 2008, 2:49:49 PM7/20/08
to Prototype & script.aculo.us
i'm not very skilled in js, which is obviously why i was drawn to
scriptaculous. in the ajax.autocompleter options how do I denote the
'element' for the 'select' option?

I have an autocompleter that shows members names and state of
residence, but I only want the name to be put in the input box when
selected.

i use php, and my page code is below:

while($row = mysql_fetch_assoc($result)){
echo "<li id='";
echo $row["member_id"];
echo "'><img src='images/members/";
echo $row["member_id"];
echo ".jpg' width='25px' /><div id='selected_text'>";
echo $row["first_name"];
echo "</div><div id='unselected_text'>";
echo $row["state"];
echo "</div></li>";
}


<script type='text/javascript'>
new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "path/
to/dir", {select:document.getElementById("selected_text")});
</script>

And this is still putting both the first name and state in the input
box when I select an option.

ColinFine

unread,
Jul 21, 2008, 9:02:18 AM7/21/08
to Prototype & script.aculo.us
That's what 'informal' is for.

Any text in the 'li' goes into the box, *except* text inside an
element (usually a span) with class 'informal'.

Bobby Brown

unread,
Jul 21, 2008, 5:50:40 PM7/21/08
to Prototype & script.aculo.us
thanks so much, that worked great. could you point me to the
documentation for that?

so..... what is the "select" option for then? because obviously i'm
not understanding it correctly.

ColinFine

unread,
Jul 22, 2008, 7:14:48 AM7/22/08
to Prototype & script.aculo.us


On Jul 21, 10:50 pm, Bobby Brown <browne...@gmail.com> wrote:
> thanks so much, that worked great. could you point me to the
> documentation for that?
>
http://github.com/madrobby/scriptaculous/wikis/ajax-autocompleter,
section "Server return".

> so..... what is the "select" option for then? because obviously i'm
> not understanding it correctly.
>
I've never noticed the 'select' option before. Looking at the code it
seems to be intended as a alternative to 'informal'; but it must be a
string containing a classname. However I'm a little dubious that it
behaves right. The relevant lines are:
if (this.options.select) {
var nodes = $(selectedElement).select('.' + this.options.select)
|| [];
if(nodes.length>0) value = Element.collectTextNodes(nodes[0],
this.options.select);
} else
value = Element.collectTextNodesIgnoreClass(selectedElement,
'informal');

which seems to say to me that it gets all the nodes with the given
class, and then takes the text nodes out of the first of them (only).
The second argument to collectTextNodes is completely ignored. So this
looks like a bit of a mess to me, as well as being inadequately
documented.

If I'm right, you can't do it the way you want, because 'selected'
will only take a class; but then it is almost a duplicate of
'informal', so it doesn't look as if it's been thought out. However,
what you're trying to do wouldn't work in any case, because you'd have
duplicated id's "selected_text" in each <li>. If you made it
<div class='selected_text'>
and then
{select:"selected_text}
I think it will work. But having looked at the code, I would avoid
'select'!
Reply all
Reply to author
Forward
0 new messages