Skip to content

Commit

Permalink
ProposalField: always send the correct acceptInput event
Browse files Browse the repository at this point in the history
The ProposalField can accept customText, i.e. a value with no
corresponding lookupRow. If the triggered acceptInput-event of the
ProposalField is marked with acceptByLookupRow the event sent to the
server contains a lookupRow property. Ensure that there is no lookupRow
property in an event for a custom text in order to make handling of a
lookupRow property with value null obsolete.

369873
  • Loading branch information
fschinkel committed Apr 5, 2024
1 parent 92ecdd3 commit 4846ee5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 34 deletions.
Expand Up @@ -170,6 +170,12 @@ export default class ProposalField extends SmartField {
}

_acceptInput(sync, searchText, searchTextEmpty, searchTextChanged, selectedLookupRow) {
if (this.touchMode) {
$.log.isDebugEnabled() && $.log.debug('(ProposalField#_acceptInput) Always send acceptInput for touch field');
this._inputAccepted(true, !!selectedLookupRow);
return;
}

// Do nothing when search text is equals to the text of the current lookup row
if (!selectedLookupRow && this.lookupRow && this.lookupRow.text === searchText) {
$.log.isDebugEnabled() && $.log.debug('(ProposalField#_acceptInput) unchanged: text is equals. Close popup');
Expand Down
13 changes: 6 additions & 7 deletions eclipse-scout-core/src/form/fields/smartfield/SmartField.js
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010-2022 BSI Business Systems Integration AG.
* Copyright (c) 2010-2024 BSI Business Systems Integration AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -232,12 +232,6 @@ export default class SmartField extends ValueField {
this._flushLookupStatus();
this._clearPendingLookup();

if (this.touchMode) {
$.log.isDebugEnabled() && $.log.debug('(SmartField#acceptInput) Always send acceptInput for touch field');
this._inputAccepted();
return;
}

return this._acceptInput(sync, searchText, searchTextEmpty, searchTextChanged, selectedLookupRow);
}

Expand Down Expand Up @@ -287,6 +281,11 @@ export default class SmartField extends ValueField {
* @param [sync] optional boolean value (default: false), when set to true acceptInput is not allowed to start an asynchronous lookup for text search
*/
_acceptInput(sync, searchText, searchTextEmpty, searchTextChanged, selectedLookupRow) {
if (this.touchMode) {
$.log.isDebugEnabled() && $.log.debug('(SmartField#_acceptInput) Always send acceptInput for touch field');
this._inputAccepted();
return;
}

let unchanged = false;
if (this.removing) {
Expand Down
@@ -1,24 +1,20 @@
/*
* Copyright (c) 2014-2017 BSI Business Systems Integration AG.
* Copyright (c) 2010-2024 BSI Business Systems Integration AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
* https://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* BSI Business Systems Integration AG - initial API and implementation
*/
package org.eclipse.scout.rt.ui.html.json.form.fields.smartfield;

import org.eclipse.scout.rt.client.ui.form.fields.IValueField;
import org.eclipse.scout.rt.client.ui.form.fields.smartfield.IProposalField;
import org.eclipse.scout.rt.client.ui.form.fields.smartfield.ISmartField;
import org.eclipse.scout.rt.platform.util.Assertions;
import org.eclipse.scout.rt.ui.html.IUiSession;
import org.eclipse.scout.rt.ui.html.json.IJsonAdapter;
import org.eclipse.scout.rt.ui.html.json.JsonEvent;
import org.eclipse.scout.rt.ui.html.json.JsonProperty;
import org.json.JSONObject;

public class JsonProposalField<VALUE, MODEL extends IProposalField<VALUE>> extends JsonSmartField<VALUE, MODEL> {

Expand Down Expand Up @@ -60,25 +56,4 @@ protected Object valueToJson(VALUE value) {
protected void setValueFromUI(Object value) {
getModel().getUIFacade().setValueAsStringFromUI((String) value);
}

@Override
protected void handleUiAcceptInput(JsonEvent event) {
JSONObject data = event.getData();
if (data.has(IValueField.PROP_DISPLAY_TEXT)) {
this.handleUiDisplayTextChange(data);
}
if (data.has(IValueField.PROP_ERROR_STATUS)) {
this.handleUiErrorStatusChange(data);
}
// The difference to the smart-field is that the proposal-field
// can receive lookup-row and value in a single event. For instance:
// lookupRow=null, value=Foo (in case a custom text has been set)
if (data.has(ISmartField.PROP_LOOKUP_ROW)) {
this.handleUiLookupRowChange(data);
}
if (data.has(IValueField.PROP_VALUE)) {
handleUiValueChange(data);
}
}

}

0 comments on commit 4846ee5

Please sign in to comment.