wrap an input type="submit" to a button

484 views
Skip to first unread message

zizou84

unread,
Mar 22, 2010, 2:58:28 PM3/22/10
to Google Web Toolkit
Hi
I have a button in my html code:
<input name="commit" value="Sign In" type="submit" id="loginButton">
i woul like to wrap it to a button:
Button loginButton=Button.wrap(DOM.getElementById("loginButton"));
but i am getting an exception:
java.lang.AssertionError: null
at com.google.gwt.dom.client.ButtonElement$.as(ButtonElement.java:
33)
at com.google.gwt.user.client.ui.Button.<init>(Button.java:115)
at com.google.gwt.user.client.ui.Button.wrap(Button.java:56)

How could i wrap my html button to a button object

Thomas Broyer

unread,
Mar 22, 2010, 7:19:19 PM3/22/10
to Google Web Toolkit

You can't. The Button widget uses a <button> element.
In your case, I'd change the HTML into:
<button name="commit" type="submit"id="loginButton">Sign In</
button>
and then use a SubmitButton.wrap(...)
Or, probably better in 99% cases, don't wrap the button into a widget:
what's your use-case? given that it's a submit button you'd better
handle form submission than clicks on the button (typing the enter key
from within a text input might trigger form submit without actually
simulating a click on the submit button, depends on browsers), and
there's no real advantage to using widgets instead of DOM elements
apart from events.

Reply all
Reply to author
Forward
0 new messages