Thanks Shawn, That helps a lot. I'll poke around with your suggestions.
Cheers, Levi On Aug 18, 2009, at 11:42, Shawn Brownfield (via Nabble) wrote: > > > > The short of this is that there doesn't appear to be a really clean > way > to do this, though I'd love to be proved wrong. Here are a few > options > I see: > > Option1: The most straightforward way to submit a form with a zone via > Ajax would be to programatically click the submit button via > Javascript: > > $(submit_id).click(); > > This would ensure that all the relevant Javascript that Tapestry adds > for a zone-linked form will fire. It's not the cleanest solution, but > it may work for you. One potential cavaet is the cross-browser > compatibility of submit.click() --I can't remember if this works in > IE. > > Option 2: Alternatively, if you delve into the inner workings of the > Javascript for Ajax form submission, you'll see that there's a > Prototype > observer for the custom event Tapestry.FORM_PROCESS_SUBMIT_EVENT added > to the form. So you could use Prototype's Element.fire(event) method: > > $(form_id).fire(Tapestry.FORM_PROCESS_SUBMIT_EVENT) > > I believe that this will do the Ajax form submission, but you may miss > some of the client-side validation that would occur before the submit > this way. Also it's potentially dependent on code that might change. > Haven't tested this. > > Option 3: Look into the background below (following along in > tapestry.js) and find a cleaner solution than options 1 or 2. > > Background: > - Forms get an onsubmit javascript method in > Tapestry.FormEventManager, > as defined in tapestry.js. > - The onsubmit method fires when a submit button is clicked, but not > when form.submit() is invoked from javascript. This is more about how > browsers work than how the framework works. > - After validation and preparation, the onsubmit method fires a > Tapestry.FORM_PROCESS_SUBMIT_EVENT for forms having > form.preventsubmission = true. This property is set when a form is > hooked up to a zone by Tapestry.Initializer.linkZone(). (This is also > where the Prototype observer for Tapestry.FORM_PROCESS_SUBMIT_EVENT is > attached.) > > As a note, trying to follow the code in tapestry.js in instances like > this can shed some greater light on the magic behind the framework... > Shawn > > xfile80303 wrote: >> This is exactly the same problem I am having as well. >> >> Even with the form's zone attribute set, form.submit() still does not >> trigger a form submission in which Request.isXHR() returns true. >> >> I'd love to see an answer to this one. >> >> Levi >> >> >> Inge Solvoll wrote: >> >>> Form component has a zone parameter. Use that, and the form will be >>> submitted with AJAX. >>> >>> 2009/8/18 sohu <zebra...@sohu.com> >>> >>> >>>> if like this: >>>> var myAjax = new Ajax.Request("poicenter.form", { >>>> method :'post', >>>> parameters :"c=c", >>>> onComplete :null >>>> }); >>>> tomcat will throw exception:Forms require that the request method >>>> be POST >>>> and that the t:formdata query parameter have values. >>>> >>>> if I just submit like this: form.submit(). Then isXHR() will >>>> return false >>>> and zone will not be update. >>>> >>>> any advise? >>>> 2009-08-18 >>>> >>>> >>>> >>>> sohu >>>> >>>> >>> >> >> > > > -- > Shawn Brownfield > Software Developer > Formos > 360.892.6463 > shawn.brownfi...@formos.com > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org > For additional commands, e-mail: users-h...@tapestry.apache.org > > > > ______________________________________ > View message @ > http://n2.nabble.com/How-to-submit-in-javascript-to-update-zone--tp3464147p3467530.html > > To unsubscribe from Re: How to submit in javascript to update zone?, > click (link removed) -- View this message in context: http://n2.nabble.com/How-to-submit-in-javascript-to-update-zone--tp3464147p3467609.html Sent from the Tapestry Users mailing list archive at Nabble.com.