[Catalyst] Complete example for autocomplete with HTML::FormFu, please

Alan Humphrey alan.humphrey at comcast.net
Fri Jul 1 17:18:00 GMT 2011


Firebug shows the following as the JSON content returned in their demo:

[ { "id": "Nycticorax nycticorax", "label": "Black-crowned Night Heron",
"value": "Black-crowned Night Heron" }, { "id": "Corvus cornix", "label":
"Hooded Crow", "value": "Hooded Crow" }, { "id": "Corvus corone", "label":
"Carrion Crow", "value": "Carrion Crow" }, { "id": "Corvus splendens",
"label": "House Crow", "value": "House Crow" }, { "id": "Zonotrichia
leucophrys", "label": "White-crowned Sparrow", "value": "White-crowned
Sparrow" } ]

-----Original Message-----
From: Alex Povolotsky [mailto:tarkhil at over.ru] 
Sent: Friday, July 01, 2011 10:02 AM
To: The elegant MVC web framework
Subject: Re: [Catalyst] Complete example for autocomplete with HTML::FormFu,
please

On 06/19/11 13:44, Charlie Garrison wrote:
> Good evening,
>
> On 19/06/11 at 12:18 AM +0400, Alex Povolotsky <tarkhil at over.ru> wrote:
>
>> I'm trying to make a form with autocomplete text edit field; I do 
>> understand general workflow but I still miss some simple-but-complete 
>> example.
>>
>> Can anyone please provide me with one? JQuery would be the best.
>
> Ripped and simplified from code I'm using. So can't say it's a 
> complete example, but should have all the elements you need to make it 
> work.

Well... Nearly works, BUT.

# In template
$(document).ready(function(){
         $("#addblack").autocomplete('[%
c.uri_for('/userinfo','complete_user', 'blacklist') %]');
   });

# In controller
sub complete_user  : Local : Args(1) {
     my ($self, $c, $mode) = @_;
     my $name = $c->req->param('term');
     if ($name gt '') {
         my $names;
         if ($mode eq 'blacklist') {
             $c->log->info('Autocompleting blacklist '.$name);
             $names = $c->model('Db::Account')->search({ login => { ILIKE =>
$name.'%' } },
                                                          { columns =>
[qw/login/], limit => 10, order_by => [qw/login/]});
             $c->log->info($names->count().' found');
             $c->stash->{entity} = [ map { { label => $_->login } }
$names->all() ];
         } else {
             die "Wrong mode $mode";
         }
         $c->stash->{term} = $name;
     }
     $c->forward('View::JSON');
}

It requests data; it receives data. Autocompletion does not work.


In http://jqueryui.com/demos/autocomplete/, there is NOTHING at all (I
really do hate them) about suggestions format expected by jQueryUI
autocomplete.

I've tried every combitation I've managed to invent, but no success.






More information about the Catalyst mailing list