You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Julian Wood <wo...@ucalgary.ca> on 2007/05/10 00:39:54 UTC

dojo Dialog, forms, asynchronous submission and javascript

I'm experimenting with using a dojo Dialog for form input.

I open up a dojo dialog, add some data to my fields, and then click  
on submit. Submit is just a regular old submit which submits my form  
component. My form component is asynchronous and updates some parts  
of the web page after its listener has finished. So far so good.

I also need it to close the dialog, and scrub the fields. How can I  
invoke some javascript to do this, once the asynchronous submit has  
returned successfully?

My current approach is to update a script component, which checks a  
flag (set by the form listener) to see if we just had an asynchronous  
form submission, and if true, includes a .script which takes the  
desired javascript actions.

But it seems like a lot of work (and a lot of separate pieces) just  
to invoke some javascript after the form submission. Is there a  
better way?

Thanks,

J
--
Julian Wood <wo...@ucalgary.ca>

Software Engineer
Teaching & Learning Centre
University of Calgary

http://tlc.ucalgary.ca



Re: dojo Dialog, forms, asynchronous submission and javascript

Posted by Julian Wood <wo...@ucalgary.ca>.
Ok that is quite nice. Still a few things. I'm at this point:

<initialization>
         dojo.event.connectOnce(tapestry.form, "submitAsync", function 
(e) {
        		if (e.id != "addBillableItemEventForm") return;
         	dojo.widget.byId("addBillableItemEventDialog").hide();
        		});
  </initialization>

The thing is, if validation fails, which is client side, then it pops  
up the validation error dialog, but closes the form dialog anyway  
(immediately). I'm still digging to see what I'm supposed to do to  
prevent this.

Attaching to onFormSubmit didn't appear to have any effect at all in  
my case (ie the form dialog doesn't close when you submit).

Thanks,

J


On 9-May-07, at 5:19 PM, Jesse Kuhnert wrote:

> Yes:
>
> dojo.event.connectOnce(tapestry.form, "onFormSubmit" /** or even
> "submitAsync" */, function(e){
>     // if you think it might be an issue you can double check the  
> target
> element id
>     if (evt.target.getAttribute("id") != "myExpectedId")
>          return;
>
>     dojo.widget.byId("yourDialogComponentId").hide();
>
>    //....or if you ~really~ want it gone
>    dojo.widget.byId("yourDialogComponentId").destroy();
> });
>
> That's it more or less .....All of the event connections /  
> reconnections /
> etc can be seen if you take a look at the "registerForm" function  
> in here,
> it's the core function always called by tapestry whether the form  
> is async
> or normal.
>
> http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry- 
> framework/src/js/tapestry/form.js?view=markup
>
> On 5/9/07, Julian Wood <wo...@ucalgary.ca> wrote:
>>
>> I'm experimenting with using a dojo Dialog for form input.
>>
>> I open up a dojo dialog, add some data to my fields, and then click
>> on submit. Submit is just a regular old submit which submits my form
>> component. My form component is asynchronous and updates some parts
>> of the web page after its listener has finished. So far so good.
>>
>> I also need it to close the dialog, and scrub the fields. How can I
>> invoke some javascript to do this, once the asynchronous submit has
>> returned successfully?
>>
>> My current approach is to update a script component, which checks a
>> flag (set by the form listener) to see if we just had an asynchronous
>> form submission, and if true, includes a .script which takes the
>> desired javascript actions.
>>
>> But it seems like a lot of work (and a lot of separate pieces) just
>> to invoke some javascript after the form submission. Is there a
>> better way?
>>
>> Thanks,
>>
>> J

--
Julian Wood <wo...@ucalgary.ca>

Software Engineer
Teaching & Learning Centre
University of Calgary

http://tlc.ucalgary.ca



Re: dojo Dialog, forms, asynchronous submission and javascript

Posted by Julian Wood <wo...@ucalgary.ca>.
Ok I've got this working now, by doing the validation again, though  
that doesn't seem like the optimal way to do it.

         dojo.event.connectOnce(tapestry.form, "submitAsync", function 
(e) {
             if (e.id != "addBillableItemEventForm") return;
             if (tapestry.form.validation.validateForm(dojo.byId 
(e.id), tapestry.form.forms[e.id])) {
                 dojo.widget.byId('addBillableItemEventDialog').hide();
             }
         });

Thanks,

J

On 9-May-07, at 5:19 PM, Jesse Kuhnert wrote:

> Yes:
>
> dojo.event.connectOnce(tapestry.form, "onFormSubmit" /** or even
> "submitAsync" */, function(e){
>     // if you think it might be an issue you can double check the  
> target
> element id
>     if (evt.target.getAttribute("id") != "myExpectedId")
>          return;
>
>     dojo.widget.byId("yourDialogComponentId").hide();
>
>    //....or if you ~really~ want it gone
>    dojo.widget.byId("yourDialogComponentId").destroy();
> });
>
> That's it more or less .....All of the event connections /  
> reconnections /
> etc can be seen if you take a look at the "registerForm" function  
> in here,
> it's the core function always called by tapestry whether the form  
> is async
> or normal.
>
> http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry- 
> framework/src/js/tapestry/form.js?view=markup
>
> On 5/9/07, Julian Wood <wo...@ucalgary.ca> wrote:
>>
>> I'm experimenting with using a dojo Dialog for form input.
>>
>> I open up a dojo dialog, add some data to my fields, and then click
>> on submit. Submit is just a regular old submit which submits my form
>> component. My form component is asynchronous and updates some parts
>> of the web page after its listener has finished. So far so good.
>>
>> I also need it to close the dialog, and scrub the fields. How can I
>> invoke some javascript to do this, once the asynchronous submit has
>> returned successfully?
>>
>> My current approach is to update a script component, which checks a
>> flag (set by the form listener) to see if we just had an asynchronous
>> form submission, and if true, includes a .script which takes the
>> desired javascript actions.
>>
>> But it seems like a lot of work (and a lot of separate pieces) just
>> to invoke some javascript after the form submission. Is there a
>> better way?
>>
>> Thanks,
>>
>> J
>> --
>> Julian Wood <wo...@ucalgary.ca>
>>
>> Software Engineer
>> Teaching & Learning Centre
>> University of Calgary
>>
>> http://tlc.ucalgary.ca
>>
>>
>>
>
>
> -- 
> Jesse Kuhnert
> Tapestry/Dojo team member/developer
>
> Open source based consulting work centered around
> dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

--
Julian Wood <wo...@ucalgary.ca>

Software Engineer
Teaching & Learning Centre
University of Calgary

http://tlc.ucalgary.ca



Re: dojo Dialog, forms, asynchronous submission and javascript

Posted by Jesse Kuhnert <jk...@gmail.com>.
Yes:

dojo.event.connectOnce(tapestry.form, "onFormSubmit" /** or even
"submitAsync" */, function(e){
     // if you think it might be an issue you can double check the target
element id
     if (evt.target.getAttribute("id") != "myExpectedId")
          return;

     dojo.widget.byId("yourDialogComponentId").hide();

    //....or if you ~really~ want it gone
    dojo.widget.byId("yourDialogComponentId").destroy();
});

That's it more or less .....All of the event connections / reconnections /
etc can be seen if you take a look at the "registerForm" function in here,
it's the core function always called by tapestry whether the form is async
or normal.

http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/js/tapestry/form.js?view=markup

On 5/9/07, Julian Wood <wo...@ucalgary.ca> wrote:
>
> I'm experimenting with using a dojo Dialog for form input.
>
> I open up a dojo dialog, add some data to my fields, and then click
> on submit. Submit is just a regular old submit which submits my form
> component. My form component is asynchronous and updates some parts
> of the web page after its listener has finished. So far so good.
>
> I also need it to close the dialog, and scrub the fields. How can I
> invoke some javascript to do this, once the asynchronous submit has
> returned successfully?
>
> My current approach is to update a script component, which checks a
> flag (set by the form listener) to see if we just had an asynchronous
> form submission, and if true, includes a .script which takes the
> desired javascript actions.
>
> But it seems like a lot of work (and a lot of separate pieces) just
> to invoke some javascript after the form submission. Is there a
> better way?
>
> Thanks,
>
> J
> --
> Julian Wood <wo...@ucalgary.ca>
>
> Software Engineer
> Teaching & Learning Centre
> University of Calgary
>
> http://tlc.ucalgary.ca
>
>
>


-- 
Jesse Kuhnert
Tapestry/Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com