*bump* since upload forms do not work in web2py components anyway this code could be integrated into web2py without the ajaxForm script itself
On Oct 11, 1:35 pm, selecta <gr...@delarue-berlin.de> wrote: > as I posted before I am trying to fix the issue of ajax uploads > > The problem: > upload fields do not work in ajax loaded components > > The solution: > modify web2py_ajax.html > on the top add > response.files.insert(3,URL(r=request,c='static/ > js',f='jquery.form.js')) > a bit below change the code to > > function web2py_trap_form(action,target) { > jQuery('#'+target+' form').each(function(i){ > var form=jQuery(this); > if(!form.hasClass('no_trap')){ > if(form.find('.upload').length>0){ > //using ajaxForm has the disadvantage that the header is > not returned in xhr > //can this be fixed in the ajaxForm plugin??? > form.ajaxForm({ > url: action, > success: function(data, statusText, xhr) { > complete_web2py_ajax_page(xhr, data, action, > target) > } > }); > }else{ > form.submit(function(obj){ > jQuery('.flash').hide().html(''); > web2py_ajax_page('post',action,form.serialize(),target); > return false; > }); > } > > } > });} > > function complete_web2py_ajax_page (xhr, text, action, target){ > var html=xhr.responseText; > var content=xhr.getResponseHeader('web2py-component-content'); > var command=xhr.getResponseHeader('web2py-component-command'); > var flash=xhr.getResponseHeader('web2py-component-flash'); > var t = jQuery('#'+target); > if(content=='prepend') t.prepend(html); > else if(content=='append') t.append(html); > else if(content!='hide') t.html(html); > web2py_trap_form(action,target); > web2py_ajax_init(); > if(command) eval(command); > if(flash) jQuery('.flash').html(flash).slideDown();} > > function web2py_ajax_page(method,action,data,target) { > jQuery.ajax({'type':method,'url':action,'data':data, > 'beforeSend':function(xhr) { > xhr.setRequestHeader('web2py-component- > location',document.location); > xhr.setRequestHeader('web2py-component-element',target);}, > 'complete':function(xhr,text){ > complete_web2py_ajax_page(xhr, text, action, target); > } > }); > > } > > however this still has a problem > if there is an upload field it will use ajaxForm which does some > iFrame magic to upland the uploads. by doing this it will loose the > response header and thus web2py-component-command and web2py-component- > flash ... > you can fix the flash by using > session.flash (?not sure if this is true but I think it worked) > and write the component-command directly into the returned HTML > > it would be nice if the header could be reconstructed by the ajaxform > pluginhttp://github.com/malsup/form/blob/master/jquery.form.js > somewhere around line 354 the dummy header object is constructed > I have no clue if retrieving the header and rebuilding it is even > possible because my js knowledge is still quite limited ... maybe > somebody could help me out here and tell me if it is possible or not