Quantcast
Channel: Apache Timeline
Viewing all articles
Browse latest Browse all 5648

need not-submitting button

$
0
0
Everyone,

There needs to be a way to have a Button that does not perform an HTML
submit, such as Link, which allows onClick() handling instead of onSubmit().

Your first response will probably tell me to RTFM and
setDefaultFormProcessing(false). :) But hear me out. If I have a submit
button <button wicket:id="cancel" type="submit"...> in the HTML, and set
an <input> as required in the HTML, then modern browsers will be so nice
as to pop up a little flyover bubble pointing right at the field in
question, and say, "You need to fill in this field." The problem is that
the cancel button <button wicket:id="cancel" type="submit"...> will also
cause this browser response, even with setDefaultFormProcessing(false)
in the code, because the browser does this validation before submission
even occurs.

I can short-circuit browser validation on cancellation by using <button
wicket:id="cancel" type="reset"...> in the HTML, but then my
Button.onSubmit() code in Java won't get called!

I can work around this by using Link in the code instead of Button,
using <button> with type="reset" in the HTML, and overriding onClick()
in the Java code. But it seems strange (and semantically silly) to use a
Button in one instance and Link in another, just to get different submit
activity---that is, unless all Wicket Buttons are really SubmitButtons.

In fact, that's what I'm getting to: a Button is a button, and it should
have an onClick() method just like a link. Only a specialized
SubmitButton should have an onSubmit(). A normal Button shouldn't cause
automatic submission of the form just because I used a Button instead of
a Link.

You may say that I should turn off required in the HTML so as to disable
all browser validation, and let Wicket take care of all validation for
consistency. There is some validity to this, but the flyover
notifications the browser uses for empty required fields are so pretty
and so much more user-friendly...

Garret

Viewing all articles
Browse latest Browse all 5648

Trending Articles