Non-Submit Button Not Getting Called from Form

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Non-Submit Button Not Getting Called from Form

eugenebalt
It's something simple that I'm forgetting, but my non-Submit button (e.g. "Cancel") is not getting called from my Form.

The button is a simple Button, not Ajax.


My HTML (using [] to avoid rendering here):

[form wicket:id=".." ]
  [input wicket:id="btnReturn" type="button" value="Return to Home Page" style="width: 300px" /]
[/form]

My Java:

        add(new Button("btnReturn") {

                @Override
                public void onSubmit() {
                    System.out.println("Clicked");
               }

            });


Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Non-Submit Button Not Getting Called from Form

hariharansrc
Actually what you will do when clicking cancel override onSubmit event similarly like other buttons

https://cwiki.apache.org/WICKET/multiple-submit-buttons.html
Reply | Threaded
Open this post in threaded view
|

Re: Non-Submit Button Not Getting Called from Form

Christian Huber
In reply to this post by eugenebalt
Hi!

Try setting the cancel button's type to "submit" instead of "button",
then the onSubmit method should be called. Though you might have to
disable default form processing for the cancel button, depending on your
form.

HTH, Chris

--
The Sanity Resort <http://sanityresort.blogspot.com/>

Am 30.07.2011 02:45, schrieb eugenebalt:

> It's something simple that I'm forgetting, but my non-Submit button (e.g.
> "Cancel") is not getting called from my Form.
>
> The button is a simple Button, not Ajax.
>
>
> My HTML (using [] to avoid rendering here):
>
> [form wicket:id=".." ]
>    [input wicket:id="btnReturn" type="button" value="Return to Home Page"
> style="width: 300px" /]
> [/form]
>
> My Java:
>
>          add(new Button("btnReturn") {
>
>                  @Override
>                  public void onSubmit() {
>                      System.out.println("Clicked");
>                 }
>
>              });
>
>
> Thanks
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Non-Submit-Button-Not-Getting-Called-from-Form-tp3705651p3705651.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>


<http://sanityresort.blogspot.com/>
Reply | Threaded
Open this post in threaded view
|

Re: Non-Submit Button Not Getting Called from Form

eugenebalt
I can't make it Submit, I already have another Submit button. This is button #2. I need to override its click behavior, and for some reason I'm not catching it.
Reply | Threaded
Open this post in threaded view
|

Re: Non-Submit Button Not Getting Called from Form

Christian Huber
If you check the link sent by hariharansrc
https://cwiki.apache.org/WICKET/multiple-submit-buttons.html you see an
example with two submit buttons. The difference to your example, as far
as i can see, is that your second button has not the submit type. To my
understanding a button that is not of the submit type does not fire it's
onSubmit method when clicked. Instead those usually have an onClick-Script.

Do you get an error when you try to add two submit buttons?
--
The Sanity Resort <http://sanityresort.blogspot.com/>

Am 30.07.2011 14:39, schrieb eugenebalt:

> I can't make it Submit, I already have another Submit button. This is button
> #2. I need to override its click behavior, and for some reason I'm not
> catching it.
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Non-Submit-Button-Not-Getting-Called-from-Form-tp3705651p3706227.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
Reply | Threaded
Open this post in threaded view
|

Re: Non-Submit Button Not Getting Called from Form

eugenebalt
Hi Christian, yes I see what you're saying. I can have 2 submit buttons with separate onSubmit()'s.

But I found an easier solution: to make the Cancel button an AjaxFallbackLink with an onClick(). That seems to work for me and I don't have to redo my main Form onSubmit. An AjaxFallbackLink can be mapped to a button, it seems.

Thanks