]> source.dussan.org Git - vaadin-framework.git/commitdiff
#5064 - NativeSelect with nullSelectionAllowed==false does not work properly
authorArtur Signell <artur.signell@itmill.com>
Mon, 27 Dec 2010 10:04:20 +0000 (10:04 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 27 Dec 2010 10:04:20 +0000 (10:04 +0000)
svn changeset:16642/svn branch:6.5

src/com/vaadin/terminal/gwt/client/ui/VNativeSelect.java

index 5e47ac571ec12960934c574971329a571dc2e64c..f9c15c49ad7d272a63259725a364234c47119ed4 100644 (file)
@@ -18,6 +18,8 @@ public class VNativeSelect extends VOptionGroupBase implements Field {
 
     protected TooltipListBox select;
 
+    private int temporaryNullValueIndex = -1;
+
     public VNativeSelect() {
         super(new TooltipListBox(false), CLASSNAME);
         select = (TooltipListBox) optionsContainer;
@@ -33,6 +35,8 @@ public class VNativeSelect extends VOptionGroupBase implements Field {
         select.setClient(client);
         select.setEnabled(!isDisabled() && !isReadonly());
         select.clear();
+        temporaryNullValueIndex = -1;
+
         if (isNullSelectionAllowed() && !isNullSelectionItemAvailable()) {
             // can't unselect last item in singleselect mode
             select.addItem("", null);
@@ -52,6 +56,7 @@ public class VNativeSelect extends VOptionGroupBase implements Field {
             // remove when something is selected
             select.insertItem("", null, 0);
             select.setItemSelected(0, true);
+            temporaryNullValueIndex = 0;
         }
         if (BrowserInfo.get().isIE6()) {
             // lazy size change - IE6 uses naive dropdown that does not have a
@@ -81,9 +86,10 @@ public class VNativeSelect extends VOptionGroupBase implements Field {
             client.updateVariable(id, "selected", new String[] { ""
                     + getSelectedItem() }, isImmediate());
         }
-        if (!isNullSelectionAllowed() && "null".equals(select.getValue(0))) {
+        if (temporaryNullValueIndex != -1) {
             // remove temporary empty item
-            select.removeItem(0);
+            select.removeItem(temporaryNullValueIndex);
+            temporaryNullValueIndex = -1;
         }
     }