details: https://code.openbravo.com/erp/devel/pi/rev/874862309622 changeset: 34836:874862309622 user: Augusto Mauch <augusto.mauch <at> openbravo.com> date: Fri Oct 05 11:41:53 2018 +0200 summary: Fixes issue 39373: Prevents unintended formitem value change if focus changes
There was a problem in this redraw function [1]. It did the following: 1) Get the value of the focused item (this.getFocusItem().getValue()) 2) Redraw the form (this.Super('redraw', arguments);) 3) Restore the value of the focused item if the value changed during the redraw (this.getFocusItem().setElementValue(focusItemValue);) The problem was that under some circumstances the focusedItem itself changed during the redraw, so the form items returned by this.getFocusItem() in steps 1) and 3) are different, and the value from one form item was copied into another form item. This problem has been fixed by storing in a variable the focused form item before the step 1), and the use that reference in the rest of the function instead of reinvoking this.getFocusItem() [1] https://code.openbravo.com/erp/devel/pi/file/tip/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js#l2157 diffstat: modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js | 17 +++++---- 1 files changed, 9 insertions(+), 8 deletions(-) diffs (43 lines): diff -r a4607c9c130c -r 874862309622 modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js --- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js Wed Oct 03 12:58:44 2018 -0400 +++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form.js Fri Oct 05 11:41:53 2018 +0200 @@ -11,7 +11,7 @@ * under the License. * The Original Code is Openbravo ERP. * The Initial Developer of the Original Code is Openbravo SLU - * All portions are Copyright (C) 2010-2016 Openbravo SLU + * All portions are Copyright (C) 2010-2018 Openbravo SLU * All Rights Reserved. * Contributor(s): ______________________________________. ************************************************************************ @@ -2155,22 +2155,23 @@ }, redraw: function () { - var focusItemValue; + var focusItem, focusItemValue; this._isRedrawing = true; + focusItem = this.getFocusItem(); //fetch the focus item value as it is lost sometimes during reflow. Refer issue https://issues.openbravo.com/view.php?id=24960 - if (this.getFocusItem()) { - focusItemValue = this.getFocusItem().getValue(); + if (focusItem) { + focusItemValue = focusItem.getValue(); } this.Super('redraw', arguments); delete this._isRedrawing; //reset focus item value if lost - if (focusItemValue && this.getFocusItem() && this.getFocusItem().getValue() !== focusItemValue) { - this.getFocusItem().setValue(focusItemValue); + if (focusItemValue && focusItem && focusItem.getValue() !== focusItemValue) { + focusItem.setValue(focusItemValue); } // Restore the focus item if it has been deleted because it was a number and was mistaken as an UUID - if (this.getFocusItem() && this.getFocusItem().targetEntity !== null && (/^\d+$/).test(focusItemValue) && !this.getFocusItem().getElementValue() && (!this.getFocusItem().valueMap || !this.getFocusItem().valueMap[focusItemValue])) { - this.getFocusItem().setElementValue(focusItemValue); + if (focusItem && focusItem.targetEntity !== null && (/^\d+$/).test(focusItemValue) && !focusItem.getElementValue() && (!focusItem.valueMap || !focusItem.valueMap[focusItemValue])) { + focusItem.setElementValue(focusItemValue); } if (this.selectOnFocusStored) { _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits