diff options
author | André Wegmüller | 2018-04-05 14:39:49 +0000 |
---|---|---|
committer | André Wegmüller | 2018-04-05 14:42:24 +0000 |
commit | 13f8f5322428e2a20d1af0091ffe49972999dc5e (patch) | |
tree | dc57c718a41036206fbd375382a063fc55343f72 | |
parent | 3ae607ceb303ee1323ea1d6139b1b864132322b0 (diff) | |
download | org.eclipse.scout.rt-13f8f5322428e2a20d1af0091ffe49972999dc5e.tar.gz org.eclipse.scout.rt-13f8f5322428e2a20d1af0091ffe49972999dc5e.tar.xz org.eclipse.scout.rt-13f8f5322428e2a20d1af0091ffe49972999dc5e.zip |
SmartField: fixed problem with accept proposal
In some cases an old proposal has been accepted, even though the user
has typed a new search text. Replaced some flag-magic, with a seqNo for
lookup results which is used to check if the result is the latest or
out-dated.
5 files changed, 32 insertions, 20 deletions
diff --git a/org.eclipse.scout.rt.ui.html.test/src/test/js/scout/form/fields/smartfield/SmartFieldRemoteSpec.js b/org.eclipse.scout.rt.ui.html.test/src/test/js/scout/form/fields/smartfield/SmartFieldRemoteSpec.js index d2b5e744e3..04d9b4f792 100644 --- a/org.eclipse.scout.rt.ui.html.test/src/test/js/scout/form/fields/smartfield/SmartFieldRemoteSpec.js +++ b/org.eclipse.scout.rt.ui.html.test/src/test/js/scout/form/fields/smartfield/SmartFieldRemoteSpec.js @@ -128,6 +128,7 @@ describe('SmartFieldRemote', function() { smartField.popup = scout.create('SmartFieldPopup', { parent: smartField, lookupResult: { + seqNo: 0, // must match smartField.lookupSeqNo lookupRows: [lookupRow] } }); diff --git a/org.eclipse.scout.rt.ui.html.test/src/test/js/scout/form/fields/smartfield/SmartFieldSpec.js b/org.eclipse.scout.rt.ui.html.test/src/test/js/scout/form/fields/smartfield/SmartFieldSpec.js index 5941373655..3799977bc0 100644 --- a/org.eclipse.scout.rt.ui.html.test/src/test/js/scout/form/fields/smartfield/SmartFieldSpec.js +++ b/org.eclipse.scout.rt.ui.html.test/src/test/js/scout/form/fields/smartfield/SmartFieldSpec.js @@ -289,6 +289,17 @@ describe('SmartField', function() { describe('lookup', function() { + it('should increase lookupSeqNo when a lookup is executed', function() { + var field = createFieldWithLookupCall(); + field.render(); + field.$field.focus(); + expect(field.lookupSeqNo).toBe(0); + field._lookupByTextOrAll(false, 'Bar'); + jasmine.clock().tick(500); + expect(field.lookupSeqNo).toBe(1); + expect(field.popup.lookupResult.seqNo).toBe(1); // seqNo must be set on the lookupResult of the popup + }); + it('should set error status when result has an exception', function() { var field = createFieldWithLookupCall(); field._lookupByTextOrAllDone({ diff --git a/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/ProposalField.js b/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/ProposalField.js index f18b5d8dc6..4826708214 100644 --- a/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/ProposalField.js +++ b/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/ProposalField.js @@ -101,10 +101,6 @@ scout.ProposalField.prototype._acceptByTextDone = function(result) { this._customTextAccepted(result.text); }; -scout.ProposalField.prototype._checkResetLookupRow = function(searchTextChanged) { - return this._userWasTyping; -}; - scout.ProposalField.prototype._checkSearchTextChanged = function(searchText) { return this._checkDisplayTextChanged(searchText); }; diff --git a/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/SmartField.js b/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/SmartField.js index d753365a6a..c3a4e6a41d 100644 --- a/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/SmartField.js +++ b/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/SmartField.js @@ -34,6 +34,8 @@ scout.SmartField = function() { this._notUnique = false; // used to store the error state 'not unique' which must not be showed while typing, but when the field loses focus this._lastSearchText = null; this.lookupStatus = null; + this.lookupSeqNo = 0; // used to detect if the proposal chooser contains the results of the latest lookup, or an out-dated result. + // only when the result is up-to-date, we can use the selected lookup row this._addCloneProperties(['lookupRow', 'codeType', 'lookupCall', 'activeFilter', 'activeFilterEnabled', 'activeFilterLabels', 'browseHierarchy', 'browseMaxRowCount', 'browseAutoExpandAll', 'browseLoadIncremental' @@ -176,18 +178,11 @@ scout.SmartField.prototype.acceptInput = function() { searchText = this._readSearchText(), searchTextEmpty = scout.strings.empty(searchText), searchTextChanged = this._checkSearchTextChanged(searchText), - selectedLookupRow = this.isPopupOpen() ? this.popup.getSelectedLookupRow() : null; + selectedLookupRow = this._getSelectedLookupRow(searchText); this._setProperty('displayText', searchText); this._acceptInputDeferred = $.Deferred(); this._flushLookupStatus(); - - // in case the user has typed something after he has selected a lookup row - // --> ignore the selection. - if (this._checkResetLookupRow(searchTextChanged)) { - selectedLookupRow = null; - } - this._clearPendingLookup(); if (this.touch) { @@ -199,17 +194,23 @@ scout.SmartField.prototype.acceptInput = function() { return this._acceptInput(searchText, searchTextEmpty, searchTextChanged, selectedLookupRow); }; -scout.SmartField.prototype._checkResetLookupRow = function(searchTextChanged) { - return searchTextChanged && this._userWasTyping; +scout.SmartField.prototype._getSelectedLookupRow = function(searchText) { + if (!this.isPopupOpen() || this._userWasTyping) { + return null; + } + + return this.lookupSeqNo === this.popup.lookupResult.seqNo ? + this.popup.getSelectedLookupRow() : null; }; scout.SmartField.prototype._checkSearchTextChanged = function(searchText) { - if (this.isDropdown()) { - return false; // search text cannot change - } - if (!this._userWasTyping) { - return false; + if (this.isDropdown() || !this._userWasTyping) { + return false; // search text cannot change in drop-down fields } + + // check if search text has changed since the last search, when it has changed + // we cannot use the currently selected lookup row, because these proposals are + // out-dated. var a = scout.strings.nullIfEmpty(this._firstTextLine(searchText)); var b = scout.strings.nullIfEmpty(this._lastSearchText); return !scout.strings.equalsIgnoreCase(a, b); @@ -373,6 +374,7 @@ scout.SmartField.prototype._acceptByTextDone = function(result) { * The implementation is different depending on the browseHierarchy property. */ scout.SmartField.prototype._extendResult = function(result) { + result.seqNo = this.lookupSeqNo; result.uniqueMatch = null; // Set query type on result, e.g. 'byAll' @@ -835,7 +837,7 @@ scout.SmartField.prototype._onClearIconMouseDown = function(event) { scout.SmartField.prototype._clear = function() { // don't tab next field when user clicks on clear icon (acceptInput is called later) this._tabPrevented = null; - // the state of these two flags is important. See #_checkResetLookupRow + // the state of these two flags is important. See #_checkSearchTextChanged this._lastSearchText = this._readDisplayText(); this._userWasTyping = true; this.$field.val(''); @@ -1088,6 +1090,7 @@ scout.SmartField.prototype.setActiveFilterEnabled = function(activeFilterEnabled * A wrapper function around lookup calls used to set the _lookupInProgress flag, and display the state in the UI. */ scout.SmartField.prototype._executeLookup = function(lookupFunc) { + this.lookupSeqNo++; this._lookupInProgress = true; this.setLoading(true); return lookupFunc() diff --git a/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/SmartFieldPopup.js b/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/SmartFieldPopup.js index 33ea78ef83..4ba55b4e81 100644 --- a/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/SmartFieldPopup.js +++ b/org.eclipse.scout.rt.ui.html/src/main/js/scout/form/fields/smartfield/SmartFieldPopup.js @@ -50,6 +50,7 @@ scout.SmartFieldPopup.prototype._render = function() { }; scout.SmartFieldPopup.prototype.setLookupResult = function(result) { + this._setProperty('lookupResult', result); this.proposalChooser.setLookupResult(result); }; |