[web2py] Re: smartgrid - still not resolving a problem
OK, I'll wait for the app. On Sunday, December 18, 2011 10:39:06 AM UTC-5, Massimo Di Pierro wrote: > > That is correct. I could not figure out the problem so I left "live" > in there. If you or anybody else have any time to experiment would be > great. I will soon release an app that uses this so you may want to > wait for that to test it. > > massimo > > On Dec 18, 9:29 am, Anthony wrote: > > On Saturday, December 17, 2011 11:02:49 PM UTC-5, Massimo Di Pierro > wrote: > > > > > The jquery.checkbox plugin replaces the usual checkbox with a [yes]/ > > > [no] slider. If I replace 'slide' with 'click' the [yes]/[no] behaves > > > the opposite way (yes for unchecked and no for checked). weird. > > > > Are you saying: > > > > jQuery("input[type='checkbox'].delete", target).click(...) > > > > causes your yes/no slider to misbehave, but > > > > jQuery("input[type='checkbox'].delete", target).live('click', ...) > > > > does not? What does "slide" have to do with it? > > > > What do you suggest we do with web2py.js? If we use .live('click', ...), > a > > component loaded with a delete checkbox in it will get the handler twice, > > which causes problems (that's why we originally changed it from .live to > > .click, as well as adding the 'target' context to the selector). > > > > Anthony > >
[web2py] Re: smartgrid - still not resolving a problem
That is correct. I could not figure out the problem so I left "live" in there. If you or anybody else have any time to experiment would be great. I will soon release an app that uses this so you may want to wait for that to test it. massimo On Dec 18, 9:29 am, Anthony wrote: > On Saturday, December 17, 2011 11:02:49 PM UTC-5, Massimo Di Pierro wrote: > > > The jquery.checkbox plugin replaces the usual checkbox with a [yes]/ > > [no] slider. If I replace 'slide' with 'click' the [yes]/[no] behaves > > the opposite way (yes for unchecked and no for checked). weird. > > Are you saying: > > jQuery("input[type='checkbox'].delete", target).click(...) > > causes your yes/no slider to misbehave, but > > jQuery("input[type='checkbox'].delete", target).live('click', ...) > > does not? What does "slide" have to do with it? > > What do you suggest we do with web2py.js? If we use .live('click', ...), a > component loaded with a delete checkbox in it will get the handler twice, > which causes problems (that's why we originally changed it from .live to > .click, as well as adding the 'target' context to the selector). > > Anthony
[web2py] Re: smartgrid - still not resolving a problem
On Saturday, December 17, 2011 11:02:49 PM UTC-5, Massimo Di Pierro wrote: > > The jquery.checkbox plugin replaces the usual checkbox with a [yes]/ > [no] slider. If I replace 'slide' with 'click' the [yes]/[no] behaves > the opposite way (yes for unchecked and no for checked). weird. Are you saying: jQuery("input[type='checkbox'].delete", target).click(...) causes your yes/no slider to misbehave, but jQuery("input[type='checkbox'].delete", target).live('click', ...) does not? What does "slide" have to do with it? What do you suggest we do with web2py.js? If we use .live('click', ...), a component loaded with a delete checkbox in it will get the handler twice, which causes problems (that's why we originally changed it from .live to .click, as well as adding the 'target' context to the selector). Anthony
[web2py] Re: smartgrid - still not resolving a problem
The jquery.checkbox plugin replaces the usual checkbox with a [yes]/ [no] slider. If I replace 'slide' with 'click' the [yes]/[no] behaves the opposite way (yes for unchecked and no for checked). weird. On Dec 17, 8:17 pm, Anthony wrote: > On Saturday, December 17, 2011 7:46:51 PM UTC-5, Massimo Di Pierro wrote: > > > It was click. I switched to live because click broke > > jquery.checkboxes.js plugin which I found very useful for something I > > am building. > > How did it break? Do you need the event handler to attach to elements that > are dynamically added to the DOM after the initial page load? In that case, > we may need a more sophisticated solution. > > Anthony
[web2py] Re: smartgrid - still not resolving a problem
On Saturday, December 17, 2011 7:46:51 PM UTC-5, Massimo Di Pierro wrote: > > It was click. I switched to live because click broke > jquery.checkboxes.js plugin which I found very useful for something I > am building. How did it break? Do you need the event handler to attach to elements that are dynamically added to the DOM after the initial page load? In that case, we may need a more sophisticated solution. Anthony
[web2py] Re: smartgrid - still not resolving a problem
It was click. I switched to live because click broke jquery.checkboxes.js plugin which I found very useful for something I am building. On Dec 17, 3:05 pm, Anthony wrote: > On Saturday, December 17, 2011 3:36:59 PM UTC-5, Massimo Di Pierro wrote: > > > We have this line in web2py.js: > > > jQuery("input[type='checkbox'].delete", target).live('click',function() > > { if(this.checked) if(!confirm(confirm_message)) > > this.checked=false; }); > > Actually, in this case (as with the other event handlers in web2py.js), we > don't want to use .live, .delegate, or .on. If we use any of those, when > Ajax components load in the page, they will get two versions of the event > handler (one from the parent document, and one from their target div). So, > instead, we should just use: > > .click(function() ... > > Anthony
[web2py] Re: smartgrid - still not resolving a problem
On Saturday, December 17, 2011 3:36:59 PM UTC-5, Massimo Di Pierro wrote: > > We have this line in web2py.js: > > jQuery("input[type='checkbox'].delete", target).live('click',function() > { if(this.checked) if(!confirm(confirm_message)) > this.checked=false; }); > Actually, in this case (as with the other event handlers in web2py.js), we don't want to use .live, .delegate, or .on. If we use any of those, when Ajax components load in the page, they will get two versions of the event handler (one from the parent document, and one from their target div). So, instead, we should just use: .click(function() ... Anthony
[web2py] Re: smartgrid - still not resolving a problem
We have this line in web2py.js: jQuery("input[type='checkbox'].delete", target).live('click',function() { if(this.checked) if(!confirm(confirm_message)) this.checked=false; }); what should be change it into? On Dec 16, 8:57 pm, Anthony wrote: > On Friday, December 16, 2011 5:54:54 PM UTC-5, Cliff wrote: > > > Adi, > > > $("#po_sku_sku_id").change(function(event){ > > > could also be > > > $("#po_sku_sku_id").live('change', function(event){ > > > In case the user changes it a second or third time. > > I'm not a jQuery expert, but I think the .change() handler will trigger on > every change event. The purpose of .live() is to allow the handler to be > added to elements that are not originally in the DOM at the time the > handler is defined but added dynamically at a later time (which I don't > think applies in this case). In any case, jQuery now recommends using .on() > instead of .live() as of 1.7, and .delegate() rather than .live() in older > versions (in other words, avoid .live). > > Anthony
[web2py] Re: smartgrid - still not resolving a problem
Thanks Anthony, delegate works perfectly fine :) I just saw somewhere too that live is being retired.. On top of everything I wanted to use the autocomplete feature instead of dropdown, but have to figure out the ways around when user selects the item, how to combine autocomplete events and this delegate... I'm not there yet. Struggle, at it's best :) Otherwise, Massimo and other contributors, I truly think this is the best web framework! Adi
[web2py] Re: smartgrid - still not resolving a problem
On Friday, December 16, 2011 5:54:54 PM UTC-5, Cliff wrote: > > Adi, > > $("#po_sku_sku_id").change(function(event){ > > could also be > > $("#po_sku_sku_id").live('change', function(event){ > > In case the user changes it a second or third time. > I'm not a jQuery expert, but I think the .change() handler will trigger on every change event. The purpose of .live() is to allow the handler to be added to elements that are not originally in the DOM at the time the handler is defined but added dynamically at a later time (which I don't think applies in this case). In any case, jQuery now recommends using .on() instead of .live() as of 1.7, and .delegate() rather than .live() in older versions (in other words, avoid .live). Anthony
[web2py] Re: smartgrid - still not resolving a problem
Adi, $("#po_sku_sku_id").change(function(event){ could also be $("#po_sku_sku_id").live('change', function(event){ In case the user changes it a second or third time. On Dec 16, 2:39 pm, Adi wrote: > We got it working :) The code bellow may help someone else with a similar > problem... Not sure if it's the most elegant way, but it works... > > In a controller, we created a function: > > def fn_sku(): > row=db(db.sku.id == request.vars['po_sku_id']).select().first() > sku_cpu = row.cpu > return sku_cpu > > and here is the view: > > {{extend 'layout.html'}} > {{=grid}} > > > function get_sku_cpu(sku_id) { > $.ajax({ > type: "POST", > // url: "http://127.0.0.1:8000/Wholesale/main/fn_sku";, > url: "{{=URL('main','fn_sku')}}", > data: ("po_sku_id=" + sku_id), > error: function(XMLHttpRequest, textStatus, errorThrown){ > alert(textStatus); > alert(XMLHttpRequest); > }, > success: function(result){ > $("#po_sku_cpu").val(result); > } > }); > > } > > $(document).ready(function(){ > $("#po_sku_sku_id").change(function(event){ > // alert("As you can see, the link no longer took you to jquery.com"); > var sku_id = $("#po_sku_sku_id").val(); > > get_sku_cpu(sku_id); > event.preventDefault(); > }); > > }); >
[web2py] Re: smartgrid - still not resolving a problem
We got it working :) The code bellow may help someone else with a similar problem... Not sure if it's the most elegant way, but it works... In a controller, we created a function: def fn_sku(): row=db(db.sku.id == request.vars['po_sku_id']).select().first() sku_cpu = row.cpu return sku_cpu and here is the view: {{extend 'layout.html'}} {{=grid}} function get_sku_cpu(sku_id) { $.ajax({ type: "POST", //url: "http://127.0.0.1:8000/Wholesale/main/fn_sku";, url: "{{=URL('main','fn_sku')}}", data: ("po_sku_id=" + sku_id), error: function(XMLHttpRequest, textStatus, errorThrown){ alert(textStatus); alert(XMLHttpRequest); }, success: function(result){ $("#po_sku_cpu").val(result); } }); } $(document).ready(function(){ $("#po_sku_sku_id").change(function(event){ // alert("As you can see, the link no longer took you to jquery.com"); var sku_id = $("#po_sku_sku_id").val(); get_sku_cpu(sku_id); event.preventDefault(); }); });
[web2py] Re: smartgrid - still not resolving a problem
Cliff, Would you be able to give me a sample please? I'm trying all possible combinations, but no luck... This should be one of the standard things in my mind... like populating another dropdown with cities after someone selects a state/province, and so on... but I'm not experienced w jquery and ajax at all...
[web2py] Re: smartgrid - still not resolving a problem
To expand on Anthony's post, your first drop down will have a unique id. If nothing else, you can look in the page source for it. Use the 'live' event, not 'onchange.' Onchange only fires once and your user might change his mind. Likewise, use ajax to repopulate the second dropdown after the change. On Dec 15, 7:58 pm, Anthony wrote: > You can't really pre-populate the field because you don't know the cpu > value until after the user selects the sku. So, you'll have to do this with > JS/jQuery and Ajax on the client side. Use jQuery to detect the sku > selection, and when detected, send an Ajax request to web2py to have it > look up the associated cpu. Check > outhttp://web2py.com/book/default/chapter/10#The-ajax-Functionfor some > ideas. > > Anthony > > > > > > > > On Thursday, December 15, 2011 7:08:04 PM UTC-5, Adi wrote: > > > I'm still trying to resolve my problem, and desperately need someone's > > help :) > > > When I try to add a new sku to a purchase order, I would like to > > prepopulate "CPU" field with the value from db.sku.cpu (determined by a > > dropdown). > > >http://127.0.0.1:8000/test/default/list_purchase_orders/purchase_orde... > > > Is it possible to do this through smartgrid, and how would I do it? Bellow > > is a short version of my code for this... I'm stuck... :( > > > #db.py > > db.define_table('sku', > > Field('sku_number', 'string', label=T('SKU #')), > > Field('description', 'string', label=T('Description')), > > Field('cpu', 'double'), > > Field('note', 'text'), > > format='%(sku_number)s - %(description)s', > > ) > > > db.define_table('purchase_order', > > Field('po_number', 'string'), > > ) > > > db.define_table('po_sku', > > Field('sku_id', db.sku, label=T('SKU #')), > > Field('po_id', db.purchase_order, label=T('Purchase Order > > #')), > > Field('qty', 'integer'), > > Field('cpu', 'double'), > > ) > > > # default.py > > def list_purchase_orders(): > > db.purchase_order.id.readable = False > > > db.purchase_order['_plural'] = 'Purchase Orders' > > > grid=SQLFORM.smartgrid(db.purchase_order, details=True, > > links_in_grid=True, > > maxtextlengths={'purchase_order.po_number':15}, > > maxtextlength=20, > > paginate=20, > > csv=False, > > ui='jquery-ui', > > user_signature=False, oncreate = auth.archive, > > onupdate=auth.archive) > > return dict(grid=grid)
[web2py] Re: smartgrid - still not resolving a problem
You can't really pre-populate the field because you don't know the cpu value until after the user selects the sku. So, you'll have to do this with JS/jQuery and Ajax on the client side. Use jQuery to detect the sku selection, and when detected, send an Ajax request to web2py to have it look up the associated cpu. Check out http://web2py.com/book/default/chapter/10#The-ajax-Function for some ideas. Anthony On Thursday, December 15, 2011 7:08:04 PM UTC-5, Adi wrote: > > I'm still trying to resolve my problem, and desperately need someone's > help :) > > When I try to add a new sku to a purchase order, I would like to > prepopulate "CPU" field with the value from db.sku.cpu (determined by a > dropdown). > > http://127.0.0.1:8000/test/default/list_purchase_orders/purchase_order/po_sku.po_id/1/new/po_sku > > Is it possible to do this through smartgrid, and how would I do it? Bellow > is a short version of my code for this... I'm stuck... :( > > #db.py > db.define_table('sku', > Field('sku_number', 'string', label=T('SKU #')), > Field('description', 'string', label=T('Description')), > Field('cpu', 'double'), > Field('note', 'text'), > format='%(sku_number)s - %(description)s', > ) > > db.define_table('purchase_order', > Field('po_number', 'string'), > ) > > db.define_table('po_sku', > Field('sku_id', db.sku, label=T('SKU #')), > Field('po_id', db.purchase_order, label=T('Purchase Order > #')), > Field('qty', 'integer'), > Field('cpu', 'double'), > ) > > # default.py > def list_purchase_orders(): > db.purchase_order.id.readable = False > > db.purchase_order['_plural'] = 'Purchase Orders' > > grid=SQLFORM.smartgrid(db.purchase_order, details=True, > links_in_grid=True, > maxtextlengths={'purchase_order.po_number':15}, > maxtextlength=20, > paginate=20, > csv=False, > ui='jquery-ui', > user_signature=False, oncreate = auth.archive, > onupdate=auth.archive) > return dict(grid=grid) > >