Hey stifan, I have a custom made javascript I use to load components in 
modals. It works with file uploads as long as you have jquery.form.js and 
you send it upload_form: true in the options. I usually use it in the 
onclick of buttons to open the modal with the form. Read the comments in 
the code to know how to use it.

function load_in_modal(url, modal_id, options) {
    if (typeof options === 'undefined') {
      /* Example Options.       * {title: "Add Image", upload_form: true}       
*/
      options = {};
    }

    /*     * You can remove this if you don't want to deal with file uploads.   
  * If you want to use this, the view/controller using this should     * insert 
jquery.form.js on response.files.     */
    if (Boolean(options.upload_form)) {
        $.web2py.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 === "#")) {
              /* form has no action. Use component url. */
              url = action;
            }

            if(form.find('.input-file').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) {
                  
$.web2py.disableElement(form.find($.web2py.formInputClickSelector));
                  $.web2py.hide_flash();
                  $.web2py.ajax_page('post', url, form.serialize(), target, 
form);
                  e.preventDefault();
                });
            }
          });
        };
    }
    /* end of file upload dealing code */


    /* Remember to set an id in your modal's body */
    $.web2py.component(url, $('#' + modal_id + ' .modal-body').attr('id'));

    $('#' + modal_id).modal({show: true});
    if (typeof options.title !== undefined) {
        $('#' + modal_id + ' .modal-title').text(options.title);
    }}

-- 
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