Fixes issue 17323: When you enter the product, the cursor jumps to the qty but the value in the field is not selected.
authorMartin Taal <martin.taal@openbravo.com>
Thu, 21 Jul 2011 15:51:42 +0200
changeset 13233 e0b6ed220be4
parent 13232 6f6a12817c39
child 13234 645f8193cf87
Fixes issue 17323: When you enter the product, the cursor jumps to the qty but the value in the field is not selected.
Two changes:
- when a next item gets the focus because a value in a picklist is chosen then the complete value gets selected
- when the FIC call is done the selection is stored before the form gets disabled and restored after enabling the form
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js
modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Thu Jul 21 13:09:41 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js	Thu Jul 21 15:51:42 2011 +0200
@@ -414,6 +414,9 @@
   setFocusInForm: function() {
     if (this.getFocusItem() && this.getFocusItem().isFocusable()) {
       this.getFocusItem().focusInItem();
+      if (this.getFocusItem().doRestoreSelection) {
+        this.getFocusItem().doRestoreSelection();
+      }
       this.view.lastFocusedItem = this.getFocusItem();
       return;
     }
@@ -718,7 +721,12 @@
     if (previousAllItemsDisabled !== this.allItemsDisabled) {
       if (this.getFocusItem()) {
         if (this.allItemsDisabled) {
-          this.getFocusItem().blurItem();
+          if (this.getFocusItem()) {
+            if (this.getFocusItem().doRememberSelection) {
+              this.getFocusItem().doRememberSelection();
+            }
+            this.getFocusItem().blurItem();
+          }
           this.setHandleDisabled(state);
           this.view.viewGrid.refreshEditRow();
         } else {
@@ -1254,6 +1262,14 @@
       } else {
         this.focusInItem(nextItem);
       }
+      // note the formItem.selectValue does not seem to work
+      // in all cases, it seems the browser internally
+      // checks if a mouseevent was the cause of the selection
+      // in which case the selection is not update, .select()
+      // does what we want
+      if (!isc.isA.TextAreaItem(nextItem) && nextItem.getElement()) {
+        nextItem.getElement().select();
+      }
     }
   },
   
--- a/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Thu Jul 21 13:09:41 2011 +0200
+++ b/modules/org.openbravo.userinterface.smartclient/web/org.openbravo.userinterface.smartclient/js/ob-smartclient.js	Thu Jul 21 15:51:42 2011 +0200
@@ -122,6 +122,30 @@
     this.hasFocus = true;
   },
 
+  doRememberSelection: function() {
+    var range = this.getSelectionRange();
+    this._rememberedWasValueSelected = range &&
+        range[0] < range[1] && range[1];        
+  },
+  
+  doRestoreSelection: function() {
+    if (!this._rememberedWasValueSelected) {
+      return;
+    }
+    if (this._rememberedWasValueSelected) {
+      // note this has to be done with a delay/separate thread
+      // otherwise the browser will not select the complete value
+      this.delayCall('doSelectElement');
+    }
+    delete this._rememberedWasValueSelected;
+  },
+  
+  doSelectElement: function() {
+    if (this.getElement()) {
+      this.getElement().select();
+    }
+  },
+
   blur: function(form, item){
     if (item._hasChanged && form && form.handleItemChange) {
       form.handleItemChange(this);