You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Bas Gooren <ba...@iswd.nl> on 2011/11/01 18:11:55 UTC
Handling form ajax submit on enter key in form field
Hi all,
To handle the case where somebody hits enter in a form field which has
an (Ajax)Button to submit the entire form by ajax, we used an
AjaxFormSubmitBehavior attached to the form's onsubmit in wicket 1.4.x
After upgrading to 1.5 our ajax indicator was not hidden after the ajax
request, wich asked for some investigating.
It turns out, this is what happens:
- onsubmit is called by browser and calls wicketSubmitFormById()
- that method calls Wicket.Ajax.Call.SubmitForm() which in turn calls
onsubmit again
The issue with the ajax indicator image remaining visible is simply due
to showIncrementally being called twice, and hideIncrementally only once.
But let's ignore that for now, the bigger issue is how do we properly
handle this use case? We chose a form onsubmit handler to prevent adding
an onKeyUp handler (and checking for enter key) to all form fields, as
this seems more elegant.
Having the form's onsubmit delegate to the ajaxbutton will create the
exact same problem: a loop.
How do others solve this in 1.5?
Re: Handling form ajax submit on enter key in form field
Posted by Bas Gooren <ba...@iswd.nl>.
Cool, thanks!
How about browser support for this? We've tested with current Firefox
and Chrome releases and it works like a charm. But how about IE < 9 ?
Op 2-11-2011 12:33, schreef Martin Grigorov:
> On Wed, Nov 2, 2011 at 1:29 PM, Bas Gooren<ba...@iswd.nl> wrote:
>> Hi,
>>
>> Yes we currently do
>>
>> form.add( new AjaxFormSubmitBehavior(form, "onsubmit"));
>>
>> I've been testing what you describe (enter keys calls submit button), and
>> this works.
>> 99% of the time we only have one submit button, so that's good enough for
>> us.
> You can use org.apache.wicket.markup.html.form.Form.setDefaultButton(IFormSubmittingComponent)
> if you have two or more submitting buttons.
>
>> Thanks!
>>
>> Op 1-11-2011 23:54, schreef Andrea Del Bene:
>>> Hi,
>>>
>>> if your form has just one submitting button, pressing enter key on a field
>>> should submit it by default. Anyway, I would solve this problem using a
>>> JavaScript library like JQuery rather then using a Wicket Ajax behavior. Can
>>> you give us more details about your AjaxFormSubmitBehavior? Are you using it
>>> like this:
>>>
>>> form.add( new AjaxFormSubmitBehavior("onsubmit"))
>>>> Hi all,
>>>>
>>>> To handle the case where somebody hits enter in a form field which has an
>>>> (Ajax)Button to submit the entire form by ajax, we used an
>>>> AjaxFormSubmitBehavior attached to the form's onsubmit in wicket 1.4.x
>>>>
>>>> After upgrading to 1.5 our ajax indicator was not hidden after the ajax
>>>> request, wich asked for some investigating.
>>>>
>>>> It turns out, this is what happens:
>>>> - onsubmit is called by browser and calls wicketSubmitFormById()
>>>> - that method calls Wicket.Ajax.Call.SubmitForm() which in turn calls
>>>> onsubmit again
>>>>
>>>> The issue with the ajax indicator image remaining visible is simply due
>>>> to showIncrementally being called twice, and hideIncrementally only once.
>>>>
>>>> But let's ignore that for now, the bigger issue is how do we properly
>>>> handle this use case? We chose a form onsubmit handler to prevent adding an
>>>> onKeyUp handler (and checking for enter key) to all form fields, as this
>>>> seems more elegant.
>>>> Having the form's onsubmit delegate to the ajaxbutton will create the
>>>> exact same problem: a loop.
>>>>
>>>> How do others solve this in 1.5?
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>>> For additional commands, e-mail: users-help@wicket.apache.org
>>>
>
>
Re: Handling form ajax submit on enter key in form field
Posted by Martin Grigorov <mg...@apache.org>.
On Wed, Nov 2, 2011 at 1:29 PM, Bas Gooren <ba...@iswd.nl> wrote:
> Hi,
>
> Yes we currently do
>
> form.add( new AjaxFormSubmitBehavior(form, "onsubmit"));
>
> I've been testing what you describe (enter keys calls submit button), and
> this works.
> 99% of the time we only have one submit button, so that's good enough for
> us.
You can use org.apache.wicket.markup.html.form.Form.setDefaultButton(IFormSubmittingComponent)
if you have two or more submitting buttons.
>
> Thanks!
>
> Op 1-11-2011 23:54, schreef Andrea Del Bene:
>>
>> Hi,
>>
>> if your form has just one submitting button, pressing enter key on a field
>> should submit it by default. Anyway, I would solve this problem using a
>> JavaScript library like JQuery rather then using a Wicket Ajax behavior. Can
>> you give us more details about your AjaxFormSubmitBehavior? Are you using it
>> like this:
>>
>> form.add( new AjaxFormSubmitBehavior("onsubmit"))
>>>
>>> Hi all,
>>>
>>> To handle the case where somebody hits enter in a form field which has an
>>> (Ajax)Button to submit the entire form by ajax, we used an
>>> AjaxFormSubmitBehavior attached to the form's onsubmit in wicket 1.4.x
>>>
>>> After upgrading to 1.5 our ajax indicator was not hidden after the ajax
>>> request, wich asked for some investigating.
>>>
>>> It turns out, this is what happens:
>>> - onsubmit is called by browser and calls wicketSubmitFormById()
>>> - that method calls Wicket.Ajax.Call.SubmitForm() which in turn calls
>>> onsubmit again
>>>
>>> The issue with the ajax indicator image remaining visible is simply due
>>> to showIncrementally being called twice, and hideIncrementally only once.
>>>
>>> But let's ignore that for now, the bigger issue is how do we properly
>>> handle this use case? We chose a form onsubmit handler to prevent adding an
>>> onKeyUp handler (and checking for enter key) to all form fields, as this
>>> seems more elegant.
>>> Having the form's onsubmit delegate to the ajaxbutton will create the
>>> exact same problem: a loop.
>>>
>>> How do others solve this in 1.5?
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>
--
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Handling form ajax submit on enter key in form field
Posted by Bas Gooren <ba...@iswd.nl>.
Hi,
Yes we currently do
form.add( new AjaxFormSubmitBehavior(form, "onsubmit"));
I've been testing what you describe (enter keys calls submit button),
and this works.
99% of the time we only have one submit button, so that's good enough
for us.
Thanks!
Op 1-11-2011 23:54, schreef Andrea Del Bene:
> Hi,
>
> if your form has just one submitting button, pressing enter key on a
> field should submit it by default. Anyway, I would solve this problem
> using a JavaScript library like JQuery rather then using a Wicket Ajax
> behavior. Can you give us more details about your
> AjaxFormSubmitBehavior? Are you using it like this:
>
> form.add( new AjaxFormSubmitBehavior("onsubmit"))
>> Hi all,
>>
>> To handle the case where somebody hits enter in a form field which
>> has an (Ajax)Button to submit the entire form by ajax, we used an
>> AjaxFormSubmitBehavior attached to the form's onsubmit in wicket 1.4.x
>>
>> After upgrading to 1.5 our ajax indicator was not hidden after the
>> ajax request, wich asked for some investigating.
>>
>> It turns out, this is what happens:
>> - onsubmit is called by browser and calls wicketSubmitFormById()
>> - that method calls Wicket.Ajax.Call.SubmitForm() which in turn calls
>> onsubmit again
>>
>> The issue with the ajax indicator image remaining visible is simply
>> due to showIncrementally being called twice, and hideIncrementally
>> only once.
>>
>> But let's ignore that for now, the bigger issue is how do we properly
>> handle this use case? We chose a form onsubmit handler to prevent
>> adding an onKeyUp handler (and checking for enter key) to all form
>> fields, as this seems more elegant.
>> Having the form's onsubmit delegate to the ajaxbutton will create the
>> exact same problem: a loop.
>>
>> How do others solve this in 1.5?
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
Re: Handling form ajax submit on enter key in form field
Posted by Andrea Del Bene <an...@gmail.com>.
Hi,
if your form has just one submitting button, pressing enter key on a
field should submit it by default. Anyway, I would solve this problem
using a JavaScript library like JQuery rather then using a Wicket Ajax
behavior. Can you give us more details about your
AjaxFormSubmitBehavior? Are you using it like this:
form.add( new AjaxFormSubmitBehavior("onsubmit"))
> Hi all,
>
> To handle the case where somebody hits enter in a form field which has
> an (Ajax)Button to submit the entire form by ajax, we used an
> AjaxFormSubmitBehavior attached to the form's onsubmit in wicket 1.4.x
>
> After upgrading to 1.5 our ajax indicator was not hidden after the
> ajax request, wich asked for some investigating.
>
> It turns out, this is what happens:
> - onsubmit is called by browser and calls wicketSubmitFormById()
> - that method calls Wicket.Ajax.Call.SubmitForm() which in turn calls
> onsubmit again
>
> The issue with the ajax indicator image remaining visible is simply
> due to showIncrementally being called twice, and hideIncrementally
> only once.
>
> But let's ignore that for now, the bigger issue is how do we properly
> handle this use case? We chose a form onsubmit handler to prevent
> adding an onKeyUp handler (and checking for enter key) to all form
> fields, as this seems more elegant.
> Having the form's onsubmit delegate to the ajaxbutton will create the
> exact same problem: a loop.
>
> How do others solve this in 1.5?
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org