Hi Anthony,

This solution you mention is, with some minor changes, still working in the 
current version. I've managed to get the change working in the 2.12.3 
version of web2py.js:
Change function trap_form to:

      trap_form: function(action, target) {
        /* traps any LOADed form */
        $('#' + target + ' form').each(function(i) {
          var form = $(this);
          if(form.hasClass('no_trap')) {
            return;
          }
          form.attr('data-w2p_target', target);
          var url = form.attr('action');
          if((url === "") || (url === "#") || (typeof url === 'undefined')) 
{
            /* form has no action. Use component url. */
            url = action;
          }
 /* begin change  */
     if(form.find('.upload').length>0) {
    form.ajaxForm({
      url: url,
      success: function(data, statusText, xhr) {
    jQuery('#'+target).html(xhr.responseText);
    web2py.trap_form(action, target);
    web2py.ajax_init();
      }
    });
     } else { /* end change */
          form.submit(function(e) {
            web2py.disableElement(form.find(web2py.formInputClickSelector));
            web2py.hide_flash();
            web2py.ajax_page('post', url, form.serialize(), target, form);
            e.preventDefault();
          });
 };
          form.on('click', web2py.formInputClickSelector, function(e) {
            e.preventDefault();
            var input_name = $(this).attr('name');
            if(input_name != undefined) {
              $('<input type="hidden" />').attr('name', input_name)
                .attr('value', $(this).val()).appendTo(form)
            }
            form.trigger('submit');
          });
        });
      },

Regards,

Bart

Op dinsdag 7 augustus 2012 06:43:36 UTC+2 schreef Anthony:
>
> At the end of this section 
> <http://web2py.com/books/default/chapter/29/12#Components> in the book it 
> says:
>
> *Please note:* Because Ajax post does not support multipart forms, i.e. 
>> file uploads, upload fields will not work with the LOAD component. You 
>> could be fooled into thinking it would work because upload fields will 
>> function normally if POST is done from the individual component's .load 
>> view. Instead, uploads are done with ajax-compatible 3rd-party widgets and 
>> web2py manual upload store commands.
>
>
> In the web2py cookbook 
> <http://www.packtpub.com/web2py-application-development-recipes-to-master-python-web-framework-cookbook/book>,
>  
> there is a recipe for this. The app associated with that recipe can be 
> downloaded here: 
> https://github.com/mdipierro/web2py-recipes-source/blob/master/apps/04_advanced_forms/web2py.app.upload.w2p.
>  
> It uses the jquery.form.js plugin: 
> http://jquery.malsup.com/form/#file-upload. The app includes a customized 
> web2py_ajax.js (which is named web2py.js in more recent versions of web2py) 
> with a custom version of web2py_trap_form():
>
> 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) {
>      form.ajaxForm({
>        url: action,
>        success: function(data, statusText, xhr) {
>          jQuery('#'+target).html(xhr.responseText);
>          web2py_trap_form(action,target);
>          web2py_ajax_init();
>        }
>      });
>    } else { 
>             form.submit(function(e){
>               jQuery('.flash').hide().html('');
>               web2py_ajax_page('post',action,form.serialize(),target);
>               e.preventDefault();
>             });
>    }
>    });
> }
>
> Anthony
>
> On Monday, August 6, 2012 11:49:27 PM UTC-4, Picheth wrote:
>>
>> I have a problem with the upload file using the LOAD (....., ajax = True)
>>
>>
>> please .. any help, cues or snippets of codes to accomplish this ... will 
>> be greatly appreciated
>>
>> Picheth.
>>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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/d/optout.

Reply via email to