Hi,
I want to have an autocomplete which displays the name and email
address of the contact.
But, the contact list array should be pre loaded, as described in
Rails Recipes.
Since this recipe doesn´t use any partials, I´m not sure how to
accomplish this.
It displays number.name, but I''m not sure how to make it display
number.email as well
search_page.rhtml
<input type="text" id="number_lookup"
name="number_lookup" /
<div class="auto_complete"
id="number_lookup_auto_complete">
</div>
<%= javascript_tag("new
Autocompleter.Local(''number_lookup'',
''number_lookup_auto_complete'',
numbers,
{fullSearch: true,
frequency: 0,
minChars: 2
}
);") %>
controller:
def numbers_for_lookup
@numbers = Number.find(:all, :conditions => ["company
''#{session[:user_company]}''"])
@headers[''content-type''] =
''text/javascript''
render :layout => false
end
numbers_for_lookup.rhtml:
var numbers = new Array(<%= @numbers.size %>);
<% @numbers.each_with_index do |number, index| %>
numbers[<%= index %>] = "<%= number.name %>";
<% end %>
Any suggestions to how I can display the email address as well in the
result box?
Regards,
Martin Stabenfeldt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Actually, you can use a partial. For an autocomplete list the
partial might be named something like _autocomplete.rhtml and would
contain something like the following:
<ul>
<% @numbers.each do | number | %>
<li><%= number.number %> <%= number.email %></li>
<% end %>
</ul>
I don''t have AWDR2 in front of me, but I believe it''s just a
render :partial => ''autocomplete'', :layout => false
from inside the controller.
paul
On Aug 17, 2007, at 6:32 AM, Martin wrote:
>
> Hi,
>
> I want to have an autocomplete which displays the name and email
> address of the contact.
> But, the contact list array should be pre loaded, as described in
> Rails Recipes.
> Since this recipe doesn´t use any partials, I´m not sure how to
> accomplish this.
>
> It displays number.name, but I''m not sure how to make it display
> number.email as well
>
> search_page.rhtml
>
> <input type="text" id="number_lookup"
name="number_lookup" /
>
> <div class="auto_complete"
id="number_lookup_auto_complete">
> </div>
> <%= javascript_tag("new
Autocompleter.Local(''number_lookup'',
>
''number_lookup_auto_complete'',
> numbers,
> {fullSearch: true,
> frequency: 0,
> minChars: 2
> }
> );") %>
>
> controller:
> def numbers_for_lookup
> @numbers = Number.find(:all, :conditions => ["company >
''#{session[:user_company]}''"])
> @headers[''content-type''] =
''text/javascript''
> render :layout => false
> end
>
> numbers_for_lookup.rhtml:
> var numbers = new Array(<%= @numbers.size %>);
>
> <% @numbers.each_with_index do |number, index| %>
> numbers[<%= index %>] = "<%= number.name %>";
> <% end %>
>
> Any suggestions to how I can display the email address as well in the
> result box?
>
> Regards,
> Martin Stabenfeldt
>
>
> >
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---