I'm not sure if typeahead will accept json as source but for me it worked 
the following way:
I created a string from values in which values were in double quotes and 
delimited by comma and I sent that string to the view:

For example:

source_string = '"one", "two", "three"'
return dict(sstr=source_string)

In the view just put that source string as typeahead source:

<script type="text/javascript">
$(document).ready(function(){
  var sourceString = [{{=sstr}}];

  $("#no_table_locality").typeahead({source: sourceString});
});
</script>

And it works like a charm!

On Tuesday, April 23, 2013 4:08:13 PM UTC+2, Annet wrote:
>
> I have been using jQueryUI's auto complete for a while, but I'd like to 
> switch to Bootstrap's type ahead.
>
> In the view I had the following code:
>
> <script type="text/javascript">
> $(document).ready(function(){
>   $(function() {$("#no_table_locality").autocomplete({source: 
> "{{=URL('jqueryui', 'locality_autocomplete')}}",minLength: 2});});
> });
> </script>
>
> and in a controller:
>
> def locality_autocomplete():
>     rows=db(db.locality.name.like(request.vars.term+'%'))\
>     .select(db.locality.name,distinct=True,orderby=db.locality.name
> ).as_list()
>     result=[r['name']for r in rows]
>     return response.json(result)
>
>
> I changed this code the following way:
>
> <script type="text/javascript">
> $(document).ready(function(){
>   $("#no_table_locality").typeahead({source: "{{=URL('typeahead', 
> 'locality_typeahead')}}"});
> });
> </script>
>
> and in the controller:
>
> def locality_typeahead():
>     rows=db(db.locality.name.like(request.vars.term+'%'))\
>     .select(db.locality.name,distinct=True,orderby=db.locality.name
> ).as_list()
>     result=[r['name']for r in rows]
>     return response.json(result)
>
>
> This doesn't work, most likely because the source isn't defined correctly. 
> This is what the Boostrap documentation
> says:
>
> The function is passed two arguments, the query value in the input field 
> and the process callback. The function 
> may be used synchronously by returning the data source directly or 
> asynchronously via the process callback's single argument.
>
> How do I code this correctly to get it to work. I am using Bootstrap 2.3.1
>
> Kind regards,
>
> Annet
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to