Saturday, February 28, 2009

Re: Autocomplete search on users table

I took a look at it following the URL you provided. It's exactly what
I'm supposed to build

As I'm not yet pretty familiar with AJAX/JSON Query in Cake, I guess
using the helper provided in Cake will not help too much.

> Of course, the cooler, more hip options are to postback after observing a
> change on the input, and AJAX/JSON look for data, only returning back
> strings containing the information you have partially entered. This could
> potentially be more powerful, allowing you to pass back more information
> like ID's to link to, as well as doing SQL "WHERE LIKE" matches, for
> mid-string matching.

How can I make it work, here is a piece of code from my UserController
class to retrieve users depending on what the end user entered in the
field.

if(!empty($search_txt)){
//Check if the input is an email address
if(eregi("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$",
$search_txt)) {
$conditions = array('User.email' => $search_txt);
$this->set('users', $this->paginate('User',$conditions));
}
else{
$conditions = array('OR' => array('User.firstname LIKE ' =>
'%'.$search_txt.'%', 'User.lastname LIKE ' => '%'.$search_txt.'%'));
$this->set('users', $this->paginate('User',$conditions));
}
}

I don't really know for now how to pass the variables everytime the
user input a key in the search field.


On 24 fév, 12:33, Graham Weldon <gra...@grahamweldon.com> wrote:
> My first disclaimer is that I dont use jQuery nearly as much as I want to.
> I tend towards prototype. However..
>
> http://docs.jquery.com/Plugins/Autocomplete
> This looks like a pretty good Autocomplete plugin for jQuery.
>
> It just wants an array of data that it is supposed to match to.
> Not sure how this works in searching all your data, and matching to a user.
> But as a starting point, you could return names to begin with:
>
> // Controller Code
> $names = implode('|', Set::extract('/MyModel/name',
> $this->MyModel->find('all', array('conditions' => array( ... )))));
> $this->set(compact('names'));
>
> // Javascript code
> var names = "<?php echo $names; ?>";
> $("#my_input").autocomplete(names.split('|'));
>
> Of course, the cooler, more hip options are to postback after observing a
> change on the input, and AJAX/JSON look for data, only returning back
> strings containing the information you have partially entered. This could
> potentially be more powerful, allowing you to pass back more information
> like ID's to link to, as well as doing SQL "WHERE LIKE" matches, for
> mid-string matching.
>
> Hope this gets you started.
>
> Cheers,
>
> Graham Weldon
> w.http://grahamweldon.com
> e. gra...@grahamweldon.com
> p. +61 407 017 293
>
> On Mon, 23 Feb 2009 19:59:02 -0800 (PST), Mike <mickael.he...@gmail.com>
> wrote:> Hi everyone,
>
> > I'd like to know if there is out there a component or helper using
> > JQuery to help me build a search autocomplete functionnality on a
> > users table.
>
> > I'd like the end user to be able to search a user by firstname,
> > lastname, email and phone number, everything using an autocomplete
> > text field.
>
> > Any help or start point ?
>
> > Thx
>
> --
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
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?hl=en
-~----------~----~----~----~------~----~------~--~---

No comments: