Seems like a lot of work to get the status of a checkbox but I guess changing the web2py_ajax.html ajax function to use jQuery.serialize wouldn't be truly backwards compatible since people have already implemented workarounds such as this. Oh well. I think the best option is to avoid the web2py_ajax.html ajax function use jQuery.ajax instead as it can serialize form elements properly.
On Aug 28, 10:15 am, mdipierro <[email protected]> wrote: > I would do something like this instead: > > 1) make sure all checkboxes have an ID > > 2) insert this in view > <script> > jQuery(document).ready(function() { > jQuery(':checkbox').change(function() { > var status; > if(jQuery(this).is(':checked') status='1'; else status='0'; > ajax('{{=URL(r=request,f='yourcallback')}}/'+jQuery(this).attr > ('id')+'/'+status,[],null); > });}); > > </script> > > then in controller > > def yourcallback(): > checkbox_id=request.args(0) > status=request.args(1) > ... store the status of checkbox_id.... > return None > > On Aug 28, 9:41 am, "mr.freeze" <[email protected]> wrote: > > > How about this: Forget ajaxForm and in the ajax function, if s is a > > string, it acts as a jQuery selector, otherwise it acts normally. > > That would make it more flexible: > > > function ajax(u,s,t) { > > query = ''; > > if (typeof s == "string"){ > > d = jQuery(s).serialize(); > > if(d){query = d;} > > }else{ > > pcs = []; > > for(i=0; i<s.length; i++) { > > q = jQuery("#"+s[i]).serialize(); > > if(q){pcs.push(q);} > > } > > if (pcs.length>0){query = pcs.join("&");} > > } > > jQuery.ajax({type: "POST", url: u, data: query, success: function > > (msg) { if(t==':eval') eval(msg); else jQuery("#" + t).html > > (msg); } }); > > > } > > > On Aug 28, 2:46 am, mdipierro <[email protected]> wrote: > > > > I suggest you don't send the entire form but just the state of the > > > button you clicked. It will have much faster response. > > > > Massimo > > > > On Aug 28, 12:28 am, "mr.freeze" <[email protected]> wrote: > > > > > I sent a patch to Massimo but for posterity, here is the fixed ajax > > > > function and added an ajaxForm(url,formIndex,targetResponseID) > > > > function that grabs the entire form (by index i so use 0 for single > > > > form pages): > > > > > function ajax(u,s,t) { > > > > query = []; > > > > for(i=0; i<s.length; i++) { > > > > q = jQuery("#"+s[i]).serialize(); > > > > if(q){query.push(q);} > > > > } > > > > jQuery.ajax({type: "POST", url: u, data: query.join("&"), success: > > > > function(msg) { if(t==':eval') eval(msg); else jQuery("#" + t).html > > > > (msg); } }); > > > > > } > > > > > function ajaxForm(u,i,t){ > > > > frm = jQuery("form:eq(" + i + ")"); > > > > query = 'undefined=' + i; > > > > if (frm.length==1){query = frm.serialize();} > > > > jQuery.ajax({type: "POST", url: u, data: query, success: > > > > function > > > > (msg) { if(t==':eval') eval(msg); else jQuery("#"+t).html > > > > (msg); } }); > > > > > } > > > > > On Aug 27, 10:01 pm, "mr.freeze" <[email protected]> wrote: > > > > > > I'll submit a patch. > > > > > > On Aug 27, 9:59 pm, Jose <[email protected]> wrote: > > > > > > > On 28 ago, 01:44, "mr.freeze" <[email protected]> wrote: > > > > > > > > Did you try my altered ajax function? > > > > > > > Works well!. You can add it to the trunk? > > > > > > > Jose- Hide quoted text - > > > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

