I noticed a bug in 1.1.0 release. If you place a button inside FormPanel, then if you click the button it will submit the form in all browsers except IE. You can use this code to fix the problem:
/** * Creates a button with no caption. */ public FormButton() { super(); fixButton(getElement()); }
/** * Creates a button with the given HTML caption. * * @param html * the HTML caption */ public FormButton(String html) { super(html); fixButton(getElement()); }
/** * Creates a button with the given HTML caption and click listener. * * @param html * the HTML caption * @param listener * the click listener */ public FormButton(String html, ClickListener listener) { super(html, listener); fixButton(getElement()); }
public static native void fixButton(Element e) /*-{ if (e.type == 'submit') { e.type = 'button'; } }-*/;
Thanks Alexei! Just ran into this problem, Firefox was submitting forms twice (or popping up the validation error messages twice). Your FormButton class completely fixed the problem.
> I noticed a bug in 1.1.0 release. If you place a button inside > FormPanel, then if you click the button it will submit the form in all > browsers except IE. You can use this code to fix the problem:
> /** > * Creates a button with no caption. > */ > public FormButton() { > super(); > fixButton(getElement()); > }
> /** > * Creates a button with the given HTML caption. > * > * @param html > * the HTML caption > */ > public FormButton(String html) { > super(html); > fixButton(getElement()); > }
> /** > * Creates a button with the given HTML caption and click listener. > * > * @param html > * the HTML caption > * @param listener > * the click listener > */ > public FormButton(String html, ClickListener listener) { > super(html, listener); > fixButton(getElement()); > }
> I noticed a bug in 1.1.0 release. If you place a button inside > FormPanel, then if you click the button it will submit the form in all > browsers except IE. You can use this code to fix the problem:
> /** > * Creates a button with no caption. > */ > public FormButton() { > super(); > fixButton(getElement()); > }
> /** > * Creates a button with the given HTML caption. > * > * @param html > * the HTML caption > */ > public FormButton(String html) { > super(html); > fixButton(getElement()); > }
> /** > * Creates a button with the given HTML caption and click listener. > * > * @param html > * the HTML caption > * @param listener > * the click listener > */ > public FormButton(String html, ClickListener listener) { > super(html, listener); > fixButton(getElement()); > }
According to the HTML spec http://www.w3.org/TR/html4/interact/forms.html#edef-BUTTON, the default for all <button> markup is type="submit" unless otherwise specified, which is what happens in the Button constructor when it calls DOM.createButton(). An alternative to using JSNI is to call DOM.setAttribute(button.getElement(), "type", "button").
Hi Vivian, I am having the same problem as stated in 'hoosie' message above, I implemented Alexis FormButton class and this fixed the problem.. but, the problem has just re-appeared even using the FormButton Class, do you have any suggestions as to what is causing this? and any workarounds, thanks
Vivian, the line you're suggesting fails in IE for some reason. The GWT shell tells me "Object does not support this operation". It works fine in FF, though. The code posted by sluramod works for both browsers.