[web2py] Re: Why does jquery autocomplete not work in subview form after submission?
A while back Anthony helped me solve a similar problem. I have a jqueryui controller with the sources: 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) and in the views that need the source: $(document).ready(function(){ $(function() { $("#no_table_locality").autocomplete({ source: "{{=URL('jqueryui', 'addresslocality_autocomplete')}}", minLength: 2 }); }); }); In my case $(document).ready(function() wasn't called in case of a nested view in combination with the LOAD functionality. I had to move the script to the nested view to solve the problem. Regards, Annet
[web2py] Re: Why does jquery autocomplete not work in subview form after submission?
I found a solution to this. I had to add a jQuery .on() handler for focus. Is this the best way to handle this? I guess this isn't a web2py problem, it's the nature of ajax/javascript/jquery I assume. Any way for web2py to magically fix this kind of thing? $(document).ready(function() { $(document).on("focus",'#autome',function(e) { if ( !$(this).data("autocomplete") ) { // If the autocomplete wasn't called yet: $('#autome').autocomplete({ source: function(request, response) { $.ajax({ url: "/autocomplete/default/myautocomplete.json", data: request, dataType: "json", type: "POST", success: function(data){ response(data.source)} })}}); } }); $('#autome').autocomplete({ source: function(request, response) { $.ajax({ url: "/autocomplete/default/myautocomplete.json", data: request, dataType: "json", type: "POST", success: function(data){ response(data.source)} })}}); }); On Monday, May 14, 2012 3:19:05 PM UTC-7, Larry Weinberg wrote: > > OK, here is a minimal sample app that demonstrates the problem. I'm > pretty new to web2py so maybe I'm not using the system as I should be. > Thank you for taking a look!
Re: [web2py] Re: Why does jquery autocomplete not work in subview form after submission?
There must be conflict with the callback in the autocomplete widget when used with component. Richard On Mon, May 14, 2012 at 8:58 AM, Anthony wrote: > Can you pack and attach a minimal app the reproduces the problem? > > > On Monday, May 14, 2012 2:08:47 AM UTC-4, Larry Weinberg wrote: >> >> I'm not sure if this is web2py question or javascript related issue. >> >> In an HTML view I am trying to call a subview with a form in it that has >> a jquery >> autocomplete attached to a text field in the form. >> I attach the autocomplete like this in the form view's document ready >> function: >> >> $(document).ready(function(){ >> $('#autome').autocomplete({ >> source: function(request, response) { >> $.ajax({ url: "/myapp/mycontroller/**myautocomplete.json", >> data: request, >> dataType: "json", >> type: "POST", >> success: function(data){ response(data.source)} >> })}}); >> }); >> >> It works fine the first time the form is loaded as a subview via LOAD. >> Once the form is processed through self-submission the autocomplete no >> longer works even though >> the ready function is being called again. >> >> I'm loading the view like this: >> >> >> {{=LOAD('default/ajaxsearch',**ajax=True)}} >> >> >> >> If I run the form by itself (not in a LOAD) the autocomplete works before >> and after form submission as expected. >> >> Here is the function for the inner form: >> >> def innerform(): >> items=[] >> form=FORM(DIV(TABLE(TR(INPUT(_**name='q',_id="autome",** >> requires=IS_NOT_EMPTY(),_**keepvalues=False), >>INPUT(_type='submit',_value='**Search') >> ))),_method='GET') >> if form.accepts(request.vars,**session=None): >> items = doMyStuff() >> return dict(form=form,items=items) >> >> Can anyone tell me why? >> >> Thanks >> >> >>
[web2py] Re: Why does jquery autocomplete not work in subview form after submission?
Can you pack and attach a minimal app the reproduces the problem? On Monday, May 14, 2012 2:08:47 AM UTC-4, Larry Weinberg wrote: > > I'm not sure if this is web2py question or javascript related issue. > > In an HTML view I am trying to call a subview with a form in it that has a > jquery > autocomplete attached to a text field in the form. > I attach the autocomplete like this in the form view's document ready > function: > > $(document).ready(function(){ > $('#autome').autocomplete({ > source: function(request, response) { > $.ajax({ url: "/myapp/mycontroller/myautocomplete.json", > data: request, > dataType: "json", > type: "POST", > success: function(data){ response(data.source)} > })}}); > }); > > It works fine the first time the form is loaded as a subview via LOAD. > Once the form is processed through self-submission the autocomplete no > longer works even though > the ready function is being called again. > > I'm loading the view like this: > > > {{=LOAD('default/ajaxsearch',ajax=True)}} > > > > If I run the form by itself (not in a LOAD) the autocomplete works before > and after form submission as expected. > > Here is the function for the inner form: > > def innerform(): > items=[] > > form=FORM(DIV(TABLE(TR(INPUT(_name='q',_id="autome",requires=IS_NOT_EMPTY(),_keepvalues=False), >INPUT(_type='submit',_value='Search') > ))),_method='GET') > if form.accepts(request.vars,session=None): > items = doMyStuff() > return dict(form=form,items=items) > > Can anyone tell me why? > > Thanks > > >