I've had some success with a very simple workaround for web2py-
component-command. In the form.accepts in my SQLFORM, I set a variable
'command', return it, and then in my component's view simply put

{{if command:}}
<script>
    $(document).ready(function(){
        eval({{=command}});
    });
</script>
{{pass}}

It's ugly, but it seems to work ok for simple stuff...


On Oct 25, 9:37 am, scausten <scaus...@gmail.com> wrote:
> Another bump - has anyone had any further thoughts on how to get
> web2py-component-command or web2py-component-flash working with this
> code?
>
> On Oct 13, 1:38 pm, selecta <gr...@delarue-berlin.de> wrote:
>
>
>
>
>
>
>
> > *bump*
> > sinceuploadforms 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 ofajaxuploads
>
> > > The problem:
> > >uploadfields do not work inajaxloaded 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 anuploadfield 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

Reply via email to