Fantastic! Thank you. Massimo
On May 5, 6:17 pm, Ted G <tedg...@gmail.com> wrote: > I've modified jDivLoad to incorporate the jQuery form plugin in order > to enable file uploads within forms that are part of a jDiv. I thought > I would post the change below so that whoever is working on jDiv can > incorporate this functionality in a better way than the hack I've done > for my purposes. Note that as per other discussions in this thread, > I've also added callbacks that fire on jDiv load and after successful > ajax form submission. I've done this for my implementation so that I > can specify callbacks when calling jDivLoad from javascript in my > view, instead of relying on setting the callback using jDiv.set in the > request handler. > > The important thing is that uploading of files within a jDiv now works > like a charm. > > Ted > > ---- Modified jDivLoad ---- > > function jDivLoad(target,callback,params,onLoadCmd,onSubmitCmd) { > $(target).attr('status','loading').trigger('loading',callback); > > $.ajax({'type':'post','url':callback, 'data':params, > 'beforeSend':function(xhr){ > xhr.setRequestHeader('web2py-jDiv-Name',target) }, > 'success':function(text){ $(target).html(text); }, > 'complete':function(xhr,text){ > $(document).trigger('set_form_constraints'); > $(target +' input[type="submit"]').click(function(){ > loc=xhr.getResponseHeader('Location'); > if((this.form.action=='' || this.form.action=='.') && > loc) > this.form.action=loc; > $('form').ajaxSubmit({ > 'target':target, > 'url':loc, > 'type':'post', > 'success':function(text){ if(onSubmitCmd) eval > (onSubmitCmd) }, > }); > return false; > }); > > command=xhr.getResponseHeader('web2py-jDiv-Commands'); > if(command) eval(command); > if(onLoadCmd) eval(onLoadCmd); > $(target).attr('status','loaded').trigger('loaded',callback); > } }); > > } > > On May 4, 1:25 pm, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > I agree. > > > On May 4, 2:36 pm, Ted G <tedg...@gmail.com> wrote: > > > > After some more digging, it would seem the problem with the file > > > upload failing may be that multipart forms cannot be submitted via > > > ajax. Given that file upload is a very common feature of forms, and > > > that forms are very common implementations of a partial (as shown in > > > the jDiv demos), not having file upload within a jDiv form would limit > > > it's usefulness. > > > > jQuery already has an ajax form plugin that can handle file uploads in > > > ajax forms by using a hidden iframe. Since web2py is already using > > > jQuery would it make sense to incorporate this plugin as part of the > > > jDiv functionality for submitting forms? Incorporating this plugin > > > would also open the door to other form behavior customizations on the > > > client side such as progress meters, etc, which would also be very > > > useful. > > > > Ted > > > > On May 1, 4:29 pm, Ted G <tedg...@gmail.com> wrote: > > > > > That is how I've resorted to for now as well (with the exception of > > > > the file upload part of my form not working as mentioned at start of > > > > this thread). > > > > > Your example is a good one and similar to my own. Using your example, > > > > I want to be able to re-use the FormjDiv partial in other pages of the > > > > site. It is hard to re-use FormjDiv when it is coupled to HoursjDiv on > > > > the controller side (as a result of FormjDiv refreshing HoursjDiv). > > > > Ideally, I would want to have FormjDiv trigger a Javascript function, > > > > either a specific named one I provide, or have it always call a > > > > generic function - eg. jDivLoadSuccess(target) that I can implement on > > > > the client side to take action. > > > > > In the generic case, thejDiv, upon successful submission would call > > > > jDivLoadSuccess(target) passing its own target_id. I could then use > > > > this to determine what action just took place and what action to take > > > > next. In your example, if this function was called as a result of > > > > target_FormjDiv submitting, then I would call jDivLoad > > > > ("target_HoursjDiv", myURL, null) to force a load of HoursJDiv. I > > > > could also then hide FormJDiv, refresh it, and any other actions I > > > > wish to take. > > > > > Not being forced to couplejDivbehavior together on the server side, > > > > opens up much better scenarios for customizing interaction > > > > betweenjDiv'sand re-use of thosejDiv's. > > > > > On May 1, 3:59 pm, Wes James <compte...@gmail.com> wrote: > > > > > > Right now with my time tracker i have: > > > > > > FormjDiv > > > > > HoursjDiv > > > > > Last20itemsjDiv > > > > > > When I submit FormjDiv it goes away (the lower part of thejDiv), but > > > > > it > > > > > refreshes HoursjDiv on the callback. At the end of the code for > > > > > HoursjDiv i > > > > > have it trigger FormjDiv to open it up again with a new form (like > > > > > click the > > > > > first top button) and also to refresh contents in Last20itemsjDiv. > > > > > > There's probably a better way to do this, but this works for now. > > > > > > -wj > > > > > > On Fri, May 1, 2009 at 4:52 PM, Ted G <tedg...@gmail.com> wrote: > > > > > > > On a related note: > > > > > > > What is the best way to trigger a Javascript function upon ajDivload > > > > > > or form submit within ajDiv? For example: --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to web2py@googlegroups.com To unsubscribe from this group, send email to web2py+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---