You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Emond Papegaaij <em...@gmail.com> on 2020/02/05 20:57:36 UTC

Form submit via Javascript and event handlers

Hi,

While fixing the CSP violations in the examples, I noticed a strange
situation in SubmitLink example:
http://examples8x.wicket.apache.org/compref/wicket/bookmarkable/org.apache.wicket.examples.compref.SubmitLinkPage

In this example, the internal submit link immediately submits the
form, while the external submit link shows a confirmation. This
confirmation is specified via an onsubmit on the form in the markup.
The JS for the external link explicitly checks onsubmit and calls
this, while the internal link does not check the onsubmit attribute. I
think these should match, and I would like to replace the f.submit()
call with a proper submit event trigger via Wicket.Event.fire(f,
'submit').

Does anyone know why this discrepancy exists, or is it merely an oversight?

Best regards,
Emond

Re: Form submit via Javascript and event handlers

Posted by Sven Meier <sv...@meiers.net>.
Fine by me.

Sven


On 05.02.20 22:22, Emond Papegaaij wrote:
> This is what I have in mind:
> https://github.com/apache/wicket/commit/b54938053a5bda2f4577966779d580e828f16e47
>
> I think this is better than the old situation because this triggers
> any submit handlers on the form (or any parent element via bubbling)
> not just the onsubmit attribute. It is a change in behavior though and
> might break existing applications.
>
> Emond
>
> On Wed, Feb 5, 2020 at 10:01 PM Emond Papegaaij
> <em...@gmail.com> wrote:
>> On Wed, Feb 5, 2020 at 9:57 PM Emond Papegaaij
>> <em...@gmail.com> wrote:
>>> While fixing the CSP violations in the examples, I noticed a strange
>>> situation in SubmitLink example:
>>> http://examples8x.wicket.apache.org/compref/wicket/bookmarkable/org.apache.wicket.examples.compref.SubmitLinkPage
>>>
>>> In this example, the internal submit link immediately submits the
>>> form, while the external submit link shows a confirmation. This
>>> confirmation is specified via an onsubmit on the form in the markup.
>>> The JS for the external link explicitly checks onsubmit and calls
>>> this, while the internal link does not check the onsubmit attribute. I
>>> think these should match, and I would like to replace the f.submit()
>>> call with a proper submit event trigger via Wicket.Event.fire(f,
>>> 'submit').
>>>
>>> Does anyone know why this discrepancy exists, or is it merely an oversight?
>> Doh, I can answer this myself, it's controlled via
>> shouldInvokeJavaScriptFormOnsubmit. Unfortunately, that does not work
>> with a strict CSP. What about changing this method to control the
>> switch between 'f.submit()' and 'Wicket.Event.fire(f, 'submit')'? The
>> first will not trigger any event bindings, the second will. For this,
>> the name of the method should be adjusted accordingly.
>>
>> Best regards,
>> Emond

Re: Form submit via Javascript and event handlers

Posted by Emond Papegaaij <em...@gmail.com>.
I've fixed the commit message, thanks for the feedback.

Emond

On Thu, Feb 6, 2020 at 1:05 PM Martin Grigorov <mg...@apache.org> wrote:
>
> Looks good!
>
> One nit: the commit message mentions twice
> 'should*Trigger*JavaScriptSubmitEvent'
> while the latter should be 'should*Invoke*JavaScriptFormOnsubmit'
> You can fix it in 'csp' branch before merging to master
>
> On Wed, Feb 5, 2020 at 11:22 PM Emond Papegaaij <em...@gmail.com>
> wrote:
>
> > This is what I have in mind:
> >
> > https://github.com/apache/wicket/commit/b54938053a5bda2f4577966779d580e828f16e47
> >
> > I think this is better than the old situation because this triggers
> > any submit handlers on the form (or any parent element via bubbling)
> > not just the onsubmit attribute. It is a change in behavior though and
> > might break existing applications.
> >
> > Emond
> >
> > On Wed, Feb 5, 2020 at 10:01 PM Emond Papegaaij
> > <em...@gmail.com> wrote:
> > >
> > > On Wed, Feb 5, 2020 at 9:57 PM Emond Papegaaij
> > > <em...@gmail.com> wrote:
> > > > While fixing the CSP violations in the examples, I noticed a strange
> > > > situation in SubmitLink example:
> > > >
> > http://examples8x.wicket.apache.org/compref/wicket/bookmarkable/org.apache.wicket.examples.compref.SubmitLinkPage
> > > >
> > > > In this example, the internal submit link immediately submits the
> > > > form, while the external submit link shows a confirmation. This
> > > > confirmation is specified via an onsubmit on the form in the markup.
> > > > The JS for the external link explicitly checks onsubmit and calls
> > > > this, while the internal link does not check the onsubmit attribute. I
> > > > think these should match, and I would like to replace the f.submit()
> > > > call with a proper submit event trigger via Wicket.Event.fire(f,
> > > > 'submit').
> > > >
> > > > Does anyone know why this discrepancy exists, or is it merely an
> > oversight?
> > >
> > > Doh, I can answer this myself, it's controlled via
> > > shouldInvokeJavaScriptFormOnsubmit. Unfortunately, that does not work
> > > with a strict CSP. What about changing this method to control the
> > > switch between 'f.submit()' and 'Wicket.Event.fire(f, 'submit')'? The
> > > first will not trigger any event bindings, the second will. For this,
> > > the name of the method should be adjusted accordingly.
> > >
> > > Best regards,
> > > Emond
> >

Re: Form submit via Javascript and event handlers

Posted by Martin Grigorov <mg...@apache.org>.
Looks good!

One nit: the commit message mentions twice
'should*Trigger*JavaScriptSubmitEvent'
while the latter should be 'should*Invoke*JavaScriptFormOnsubmit'
You can fix it in 'csp' branch before merging to master

On Wed, Feb 5, 2020 at 11:22 PM Emond Papegaaij <em...@gmail.com>
wrote:

> This is what I have in mind:
>
> https://github.com/apache/wicket/commit/b54938053a5bda2f4577966779d580e828f16e47
>
> I think this is better than the old situation because this triggers
> any submit handlers on the form (or any parent element via bubbling)
> not just the onsubmit attribute. It is a change in behavior though and
> might break existing applications.
>
> Emond
>
> On Wed, Feb 5, 2020 at 10:01 PM Emond Papegaaij
> <em...@gmail.com> wrote:
> >
> > On Wed, Feb 5, 2020 at 9:57 PM Emond Papegaaij
> > <em...@gmail.com> wrote:
> > > While fixing the CSP violations in the examples, I noticed a strange
> > > situation in SubmitLink example:
> > >
> http://examples8x.wicket.apache.org/compref/wicket/bookmarkable/org.apache.wicket.examples.compref.SubmitLinkPage
> > >
> > > In this example, the internal submit link immediately submits the
> > > form, while the external submit link shows a confirmation. This
> > > confirmation is specified via an onsubmit on the form in the markup.
> > > The JS for the external link explicitly checks onsubmit and calls
> > > this, while the internal link does not check the onsubmit attribute. I
> > > think these should match, and I would like to replace the f.submit()
> > > call with a proper submit event trigger via Wicket.Event.fire(f,
> > > 'submit').
> > >
> > > Does anyone know why this discrepancy exists, or is it merely an
> oversight?
> >
> > Doh, I can answer this myself, it's controlled via
> > shouldInvokeJavaScriptFormOnsubmit. Unfortunately, that does not work
> > with a strict CSP. What about changing this method to control the
> > switch between 'f.submit()' and 'Wicket.Event.fire(f, 'submit')'? The
> > first will not trigger any event bindings, the second will. For this,
> > the name of the method should be adjusted accordingly.
> >
> > Best regards,
> > Emond
>

Re: Form submit via Javascript and event handlers

Posted by Emond Papegaaij <em...@gmail.com>.
This is what I have in mind:
https://github.com/apache/wicket/commit/b54938053a5bda2f4577966779d580e828f16e47

I think this is better than the old situation because this triggers
any submit handlers on the form (or any parent element via bubbling)
not just the onsubmit attribute. It is a change in behavior though and
might break existing applications.

Emond

On Wed, Feb 5, 2020 at 10:01 PM Emond Papegaaij
<em...@gmail.com> wrote:
>
> On Wed, Feb 5, 2020 at 9:57 PM Emond Papegaaij
> <em...@gmail.com> wrote:
> > While fixing the CSP violations in the examples, I noticed a strange
> > situation in SubmitLink example:
> > http://examples8x.wicket.apache.org/compref/wicket/bookmarkable/org.apache.wicket.examples.compref.SubmitLinkPage
> >
> > In this example, the internal submit link immediately submits the
> > form, while the external submit link shows a confirmation. This
> > confirmation is specified via an onsubmit on the form in the markup.
> > The JS for the external link explicitly checks onsubmit and calls
> > this, while the internal link does not check the onsubmit attribute. I
> > think these should match, and I would like to replace the f.submit()
> > call with a proper submit event trigger via Wicket.Event.fire(f,
> > 'submit').
> >
> > Does anyone know why this discrepancy exists, or is it merely an oversight?
>
> Doh, I can answer this myself, it's controlled via
> shouldInvokeJavaScriptFormOnsubmit. Unfortunately, that does not work
> with a strict CSP. What about changing this method to control the
> switch between 'f.submit()' and 'Wicket.Event.fire(f, 'submit')'? The
> first will not trigger any event bindings, the second will. For this,
> the name of the method should be adjusted accordingly.
>
> Best regards,
> Emond

Re: Form submit via Javascript and event handlers

Posted by Emond Papegaaij <em...@gmail.com>.
On Wed, Feb 5, 2020 at 9:57 PM Emond Papegaaij
<em...@gmail.com> wrote:
> While fixing the CSP violations in the examples, I noticed a strange
> situation in SubmitLink example:
> http://examples8x.wicket.apache.org/compref/wicket/bookmarkable/org.apache.wicket.examples.compref.SubmitLinkPage
>
> In this example, the internal submit link immediately submits the
> form, while the external submit link shows a confirmation. This
> confirmation is specified via an onsubmit on the form in the markup.
> The JS for the external link explicitly checks onsubmit and calls
> this, while the internal link does not check the onsubmit attribute. I
> think these should match, and I would like to replace the f.submit()
> call with a proper submit event trigger via Wicket.Event.fire(f,
> 'submit').
>
> Does anyone know why this discrepancy exists, or is it merely an oversight?

Doh, I can answer this myself, it's controlled via
shouldInvokeJavaScriptFormOnsubmit. Unfortunately, that does not work
with a strict CSP. What about changing this method to control the
switch between 'f.submit()' and 'Wicket.Event.fire(f, 'submit')'? The
first will not trigger any event bindings, the second will. For this,
the name of the method should be adjusted accordingly.

Best regards,
Emond