[Catalyst] http://www.pcklus.nl/catalyst_auto_complete_take1.mov

michael reece mreece at sacbee.com
Fri Jul 15 18:36:59 CEST 2005


for those who can't watch the video, here's a snippet that uses Mason  
instead of TT:

the template (autocomplete):

<% $c->prototype->define_javascript_functions %>
<% $c->prototype->auto_complete_stylesheet %>

<!-- some docs on why this needs autocomplete="off" would be nice -->
<input autocomplete="off" id="complete_me" name="complete_me"  
type="text" />
<div class="auto_complete" id="complete_me_auto_complete"></div>

<% $c->prototype->auto_complete_field( 'complete_me', { url =>  
$base . 'autocomplete/suggest' } ) %>


the controller (AutoComplete.pm):

sub default : Private {
     my ( $self, $c ) = @_;
     $c->stash->{template} = 'autocomplete';
}

sub suggest : Local {
     my ( $self, $c ) = @_;
     my $complete_me = $c->req->params->{complete_me};
     my @suggestions;
     push @suggestions, "$complete_me $_" foreach (1..5);
     $c->res->output( $c->prototype->auto_complete_result 
( \@suggestions ) );
}



here's how easy it was to do the same thing with a db query:

sub suggest : Local {
     my ( $self, $c ) = @_;
     my $complete_me = $c->req->params->{complete_me};
     my @suggestions;
     if ( $complete_me ) {
         my $today = localtime->mysql_date;  # from Time::Piece::MySQL
         my @s = MyApp::CDBI::Story->search_like(headline => "$ 
{complete_me}%", pubdate => $today);
         push @suggestions, $_->headline foreach @s;
     }
     $c->res->output( $c->prototype->auto_complete_result 
( \@suggestions ) );
}



On Jul 15, 2005, at 9:14 AM, Mike McKay wrote:

>
>
>
>>> 404 *cough*. :)
>>>
>> Yes, his provider didn't liked all the traffic recently. :)
>> Here's a list of other mirrors.
>>
>
> How about a code snippet showing how easy it is? And maybe a link  
> to a site where we can try it out? 15MB doesn't work for those of  
> us on dialup!
>
> Mike
>
>
> _______________________________________________
> Catalyst mailing list
> Catalyst at lists.rawmode.org
> http://lists.rawmode.org/mailman/listinfo/catalyst
>

-----
michael reece :: web engineer :: mreece at sacbee.com





More information about the Catalyst mailing list