]> source.dussan.org Git - gwtquery.git/commitdiff
fix issue 98
authorJulien Dramaix <julien.dramaix@gmail.com>
Wed, 24 Aug 2011 22:00:39 +0000 (22:00 +0000)
committerJulien Dramaix <julien.dramaix@gmail.com>
Wed, 24 Aug 2011 22:00:39 +0000 (22:00 +0000)
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryCoreTest.java

index 60941c6b9a248fa62482f1866676d7f31daedc60..fcf4017258c4f69d0d0d09dfb3beb7e5424d6482 100644 (file)
@@ -3758,20 +3758,15 @@ public class GQuery implements Lazy<GQuery, LazyGQuery> {
       } else if ("input".equalsIgnoreCase(name)) {\r
         InputElement ie = InputElement.as(e);\r
         String type = ie.getType();\r
+        \r
         if ("radio".equalsIgnoreCase((type))\r
-            || "checkbox".equalsIgnoreCase(type)) {\r
-          if ("checkbox".equalsIgnoreCase(type)) {\r
-            for (String val : values) {\r
-              if (ie.getValue().equals(val)) {\r
-                ie.setChecked(true);\r
-              } else {\r
-                ie.setChecked(false);\r
-              }\r
+            || "checkbox".equalsIgnoreCase(type)){\r
+          ie.setChecked(false);\r
+          for (String val : values) {\r
+            if (ie.getValue().equals(val)) {\r
+              ie.setChecked(true);\r
+              break;\r
             }\r
-          } else if (ie.getValue().equals(values[0])) {\r
-            ie.setChecked(true);\r
-          } else {\r
-            ie.setChecked(false);\r
           }\r
         } else {\r
           ie.setValue(values[0]);\r
index 4aefc20ca84276cc6da135a473fc7ccb6dd45754..487af6f6619ad621f9a75f3cbfc1cb5a6b5a0407 100644 (file)
@@ -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("<select id='single'>"
+              +    "<option>Single</option>"
+              +    "<option>Single2</option>"
+              +"</select>"
+              +"<select id='multiple' multiple='multiple'>"
+              +    "<option selected='selected'>Multiple</option>"
+              +    "<option>Multiple2</option>"
+              +    "<option selected='selected'>Multiple3</option>"
+              +"</select>"
+              +"<input id='check1' type='checkbox' name='checkboxname' value='check1'> check1"
+              +"<input id='check2' type='checkbox' name='checkboxname' value='check2'> check2"
+              +"<input id='check3' type='checkbox' name='checkboxname' value='check3'> check3"
+              +"<input id='radio1' type='radio' name='r' value='radio1'> radio1"
+              +"<input id='radio2' type='radio' name='r' value='radio2'> radio2"
+              +"<input id='text'   type='text'></input>");
+    
+    $("#single",e).val("Single2");
+    SelectElement single =  SelectElement.as($("#single",e).get(0));
+    assertEquals(1, single.getSelectedIndex());
+    
+    $("#multiple",e).val("Multiple2", "Multiple3"); 
+    NodeList<OptionElement>options = 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(