From: Julien Dramaix Date: Wed, 24 Aug 2011 22:00:39 +0000 (+0000) Subject: fix issue 98 X-Git-Tag: release-1.3.2~248 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=274f65b2e494382981c98bf0d18172975301d1c4;p=gwtquery.git fix issue 98 --- diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index 60941c6b..fcf40172 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -3758,20 +3758,15 @@ public class GQuery implements Lazy { } else if ("input".equalsIgnoreCase(name)) { InputElement ie = InputElement.as(e); String type = ie.getType(); + if ("radio".equalsIgnoreCase((type)) - || "checkbox".equalsIgnoreCase(type)) { - if ("checkbox".equalsIgnoreCase(type)) { - for (String val : values) { - if (ie.getValue().equals(val)) { - ie.setChecked(true); - } else { - ie.setChecked(false); - } + || "checkbox".equalsIgnoreCase(type)){ + ie.setChecked(false); + for (String val : values) { + if (ie.getValue().equals(val)) { + ie.setChecked(true); + break; } - } else if (ie.getValue().equals(values[0])) { - ie.setChecked(true); - } else { - ie.setChecked(false); } } else { ie.setValue(values[0]); diff --git a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java index 4aefc20c..487af6f6 100644 --- a/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java +++ b/gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java @@ -29,8 +29,11 @@ import junit.framework.Assert; import com.google.gwt.dom.client.Document; import com.google.gwt.dom.client.Element; +import com.google.gwt.dom.client.InputElement; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; +import com.google.gwt.dom.client.OptionElement; +import com.google.gwt.dom.client.SelectElement; import com.google.gwt.event.dom.client.ClickEvent; import com.google.gwt.event.dom.client.ClickHandler; import com.google.gwt.junit.client.GWTTestCase; @@ -893,6 +896,50 @@ public class GQueryCoreTest extends GWTTestCase { assertFalse(JsUtils.truth(null)); assertFalse(JsUtils.truth("")); } + + public void testVal(){ + //HTML code used in this test + $(e).html("" + +"" + +" check1" + +" check2" + +" check3" + +" radio1" + +" radio2" + +""); + + $("#single",e).val("Single2"); + SelectElement single = SelectElement.as($("#single",e).get(0)); + assertEquals(1, single.getSelectedIndex()); + + $("#multiple",e).val("Multiple2", "Multiple3"); + NodeListoptions = SelectElement.as($("#multiple",e).get(0)).getOptions(); + + assertEquals(false, options.getItem(0).isSelected()); + assertEquals(true, options.getItem(1).isSelected()); + assertEquals(true, options.getItem(2).isSelected()); + + $("input",e).val("check1","check2", "radio1", "radio2" ); + assertEquals(true, InputElement.as($("#check1", e).get(0)).isChecked()); + assertEquals(true, InputElement.as($("#check2", e).get(0)).isChecked()); + assertEquals(false, InputElement.as($("#check3", e).get(0)).isChecked()); + + //radio1 should not be selected + assertEquals(false, InputElement.as($("#radio1", e).get(0)).isChecked()); + //radio1 should be selected + assertEquals(true, InputElement.as($("#radio2", e).get(0)).isChecked()); + + //radio1 should not be selected + assertEquals("check1", InputElement.as($("#text", e).get(0)).getValue()); + + } public void testWidthHeight() { $(e).html(