Saturday, April 23, 2011

Re: Another AJAX Autocomplete question

On Sat, Apr 23, 2011 at 3:25 PM, turbo2ltr <turbo2ltr@gmail.com> wrote:
> I see there are a lot of questions about implementing AJAX
> autocomplete, but I'll be dammed if every single thing on the subject
> is woefully confusing or from the mid 2000s.
>
> I go to the 1.3 cookbook under Ajax and right at the top is says
> AjaxHelper is depreciated, then it goes on to talk about those same
> things.  How can the latest version of cakePHP already be depreciated?

It's not the latest version that's deprecated, a portion of it. Pretty
normal for any software project.
http://book.cakephp.org/view/1561/Migrating-from-CakePHP-1-2-to-1-3

> I've tried about 8 different implementations of ajax autocomplete that
> I've found on the web and could not get any of them to work...mostly
> because they assumed I'm smarter than I am (not step by step
> instructions, but code snippets or pseudo code), or they were written
> for an out of date version of cake.
>
> Prototype? Scriptalicious? JQuery?  WTF are we supposed to use?

Pick your poison.
http://book.cakephp.org/view/1596/Javascript-engine-usage#!/view/1594/Using-a-specific-Javascript-engine

I recommend jQuery.

> Actually I did get this one to sorta work, sorta:
> http://cakebaker.42dh.com/2006/06/06/autocompletion-the-easy-way/

As you alluded to in the beginning, that's much to old to serve as
anything but a hint. Cake has changed a lot.

> The field I want to autocomplete is a vendor name.  But in the the
> suppliers model, the vendor name is an ID to the vendors table.  The
> autocomplete was returning the ID, not the name.  Sure it seemed easy
> to implement, but it also seemed to be limited. I couldn't figure out
> how to get the vendor name instead of the ID.

Right, so from your Supplier model, you can do
$this->Vendor->find(...). From your SuppliersController,
$this->Supplier->Vendor->find(...)

> So I beg of the community, can someone put up an up-to-date, step-by-
> step tutorial on how to properly implement AJAX autocomplete??

You needn't rely on a Cake helper to do this. The js side of it is
just handling the change event on your select list by sending an ajax
request to the server. There are several jQuery plugins built just for
this. The Cake side of it is simply receiving a string and doing a
find('list') with an, eg. "LIKE ${str}%" condition (be sure to check
that input) and sending back a list of results. Use RequestHandler and
create an ajax.ctp layout, then echo json_encode($res).

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate