You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Kenneth CH, LEE" <kl...@gmail.com> on 2009/12/22 13:44:14 UTC
[newbie] Intercepting client-side form validation/submission
Hi there,
Is there any existing facilities to trigger some custom Javascript
code _after_ validating the form?
I'm now doing it with some Javascript tricks:
===============
<form t:type="form" t:id="myform">
...
<script type="text/javascript">
Event.observe(window, "load", function() {
var f = $("myform").onsubmit;
$("myform").onsubmit = function(e) {
return f(e) && customFunction();
};
});
</script>
</form>
...
<script type="text/javascript">
function customFunction() {
//return true to submit
}
</script>
===============
Notice that the custom function is only called _after_ validation
_and_ only if it was successful.
Since this is all boiler-plate I'm going to make it a component that
can be nested within <t:form/>, but before that I want to make sure
I'm not reinventing something that already exist. Or just tell me if
I'm going the wrong way and the _proper_ way to do it.
Your input is much appreciated.
Kenneth
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [newbie] Intercepting client-side form validation/submission
Posted by Ashwanth Kumar <as...@gmail.com>.
Use Event.observe for the form and use the validation with custom JS of
urs...
HTH
- Ashwanth Kumar
On Wed, Dec 23, 2009 at 3:48 PM, Kenneth CH, LEE <kl...@gmail.com> wrote:
> There is a submit button within the form. I could not attach the code
> in onclick handler because I want it to run only if the form is valid.
>
> 2009/12/22 Ashwanth Kumar <as...@gmail.com>:
> > On Tue, Dec 22, 2009 at 6:14 PM, Kenneth CH, LEE <kl...@gmail.com>
> wrote:
> >
> >> Hi there,
> >>
> >
> > Hello,
> >
> >
> >>
> >> Is there any existing facilities to trigger some custom Javascript
> >> code _after_ validating the form?
> >>
> >> I'm now doing it with some Javascript tricks:
> >> ===============
> >> <form t:type="form" t:id="myform">
> >> ...
> >> <script type="text/javascript">
> >> Event.observe(window, "load", function() {
> >> var f = $("myform").onsubmit;
> >> $("myform").onsubmit = function(e) {
> >> return f(e) && customFunction();
> >> };
> >> });
> >> </script>
> >> </form>
> >> ...
> >> <script type="text/javascript">
> >> function customFunction() {
> >> //return true to submit
> >> }
> >> </script>
> >> ===============
> >>
> >
> > When exactly do u submit ur form??
> >
> >
> >> Notice that the custom function is only called _after_ validation
> >> _and_ only if it was successful.
> >>
> >
> > Well, if you want to do a custom JS, u can do a Zone Update of the Form,
> > then observe Tapestry.ZONE_UPDATED_EVENT, for doing some some custom JS!
> > But, that happens only after form submission and not before that!
> >
> > HTH
> > - Ashwanth Kumar
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>
Re: [newbie] Intercepting client-side form validation/submission
Posted by "Kenneth CH, LEE" <kl...@gmail.com>.
There is a submit button within the form. I could not attach the code
in onclick handler because I want it to run only if the form is valid.
2009/12/22 Ashwanth Kumar <as...@gmail.com>:
> On Tue, Dec 22, 2009 at 6:14 PM, Kenneth CH, LEE <kl...@gmail.com> wrote:
>
>> Hi there,
>>
>
> Hello,
>
>
>>
>> Is there any existing facilities to trigger some custom Javascript
>> code _after_ validating the form?
>>
>> I'm now doing it with some Javascript tricks:
>> ===============
>> <form t:type="form" t:id="myform">
>> ...
>> <script type="text/javascript">
>> Event.observe(window, "load", function() {
>> var f = $("myform").onsubmit;
>> $("myform").onsubmit = function(e) {
>> return f(e) && customFunction();
>> };
>> });
>> </script>
>> </form>
>> ...
>> <script type="text/javascript">
>> function customFunction() {
>> //return true to submit
>> }
>> </script>
>> ===============
>>
>
> When exactly do u submit ur form??
>
>
>> Notice that the custom function is only called _after_ validation
>> _and_ only if it was successful.
>>
>
> Well, if you want to do a custom JS, u can do a Zone Update of the Form,
> then observe Tapestry.ZONE_UPDATED_EVENT, for doing some some custom JS!
> But, that happens only after form submission and not before that!
>
> HTH
> - Ashwanth Kumar
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org
Re: [newbie] Intercepting client-side form validation/submission
Posted by Ashwanth Kumar <as...@gmail.com>.
On Tue, Dec 22, 2009 at 6:14 PM, Kenneth CH, LEE <kl...@gmail.com> wrote:
> Hi there,
>
Hello,
>
> Is there any existing facilities to trigger some custom Javascript
> code _after_ validating the form?
>
> I'm now doing it with some Javascript tricks:
> ===============
> <form t:type="form" t:id="myform">
> ...
> <script type="text/javascript">
> Event.observe(window, "load", function() {
> var f = $("myform").onsubmit;
> $("myform").onsubmit = function(e) {
> return f(e) && customFunction();
> };
> });
> </script>
> </form>
> ...
> <script type="text/javascript">
> function customFunction() {
> //return true to submit
> }
> </script>
> ===============
>
When exactly do u submit ur form??
> Notice that the custom function is only called _after_ validation
> _and_ only if it was successful.
>
Well, if you want to do a custom JS, u can do a Zone Update of the Form,
then observe Tapestry.ZONE_UPDATED_EVENT, for doing some some custom JS!
But, that happens only after form submission and not before that!
HTH
- Ashwanth Kumar