[Catalyst] jquery autocomplete and JSON

Armin Wenz wenz at ub.uni-frankfurt.de
Fri Apr 29 10:55:24 GMT 2011


Hi all,

I've read the last years the thread about "Using Jquery UI Autocomplete 
widget with Catalyst::View::JSON". And still got a problem:

My template is:
<script type="text/javascript" 
src="/static/js/jquery.validate.min.js"></script>
<script type="text/javascript" 
src="/static/js/jquery.bgiframe.min.js"></script>
<script type="text/javascript" 
src="/static/js/jquery.ajaxQueue.js"></script>
<script type="text/javascript" 
src="/static/js/jquery.autocomplete.min.js"></script>
<script type="text/javascript" 
src="/static/js/thickbox-compressed.js"></script>
<link rel="stylesheet" href="[% 
c.uri_for('/static/css/jquery/jquery.autocomplete.css') %]" ></link>

<script type="text/javascript">
<!--
   $(document).ready(function(){
   $("#model").autocomplete("[% c.uri_for('/model/modellist') %]", {
         selectFirst: false,
         width: 260,
   });
   });
//-->
</script>

<form id="commentForm" class="cmxform" method="post" action="[% 
c.uri_for('save') %]">
<table>
<tr>
<td class="label">Modell</td>
<td class="data"><input id="model" name="model" size="40"  /></td>
</tr>
</table>
</form>


In my Controller
sub modellist :Local {
     my ( $self, $c ) = @_;
     my @aoh = ( { value => "1", label => "betty", },
                 { value => "2", label => "jane", },
                 { value => "3", label => "marge", },
               );
     $c->stash->{json} = \@aoh;
     $c->forward('View::JSON');
}

When I enter a character into the input-field, the above URL is called 
and the follwing data is returned:

[{"value":"1","label":"betty"},{"value":"2","label":"jane"},{"value":"3","label":"marge"}]

But I don't get the expected dropdown, where I can select any of the 
returned data.

As far as the returned data seems to be okay, I assume that the mistake 
lies within the template (maybe I forgot something?)

Can anybody give me a hint?

Thanks in advance.

-- 

Armin Wenz

Universitätsbibliothek Johann Christian Senkenberg
Telefon: 069-798-39504



More information about the Catalyst mailing list