Skip to content

Commit

Permalink
ProposalField: fix validation errors
Browse files Browse the repository at this point in the history
If a potential value that is not accepted by the validator of a
ProposalField is passed to the field, the display text needs to change
while the value stays the same.
If this value comes from a selected lookupRow, the lookupRow will be set
and therefore, the formatting needs to consider it.
If this value comes from a touch popup, there are several things that
need to be considered:
* The lookupRow must not trigger any value changed logic, as setting a
  value that does not pass validation will reset the value to the
  previous one. Otherwise, if the new lookupRow is null it will set the
  value of the field to null and therefore the reset-logic after a
  failed validation resets the value to null as the former value is
  already lost.
* The displayText needs to be set without exception, as it can differ
  from the value. Consider the value 'info' for which a validator adds
  an error status with severity info and another value 'throw' for which
  the validation fails. Switching between these two values will never
  change the value, it will always stay 'info'. But what needs to change
  are the displayText and the error status. Therefore, the value needs
  to be set again when switching from 'throw' back to 'info' as the
  validator needs to run in order to add the info-error status. The
  displayText needs to be set to support the 'info'>'throw' case as
  setting a value 'throw' will never change the displayText it needs to
  be transferred explicitly from the touch popup.
* The value needs to be set without exception, even if it is identical
  to the current value. See example for displayText.
To support the 'throw' > 'info' case from the previous example correctly
for Scout Classic, an input needs to be accepted and all listeners need
to be informed if the search text changed to the text of the current
lookupRow. Consider the previous example and the inputs "lookup 'info'"
> "lookup 'throw'" > "write 'info'". While writing 'info', the 'info'
lookupRow is still present and the searchText changes from 'throw' to
'info' and therefore, the listener in the adapter needs to be triggered
in order to validate 'info' again on the ui server.

369873
  • Loading branch information
fschinkel committed Apr 5, 2024
1 parent 4846ee5 commit 6f89d63
Show file tree
Hide file tree
Showing 2 changed files with 438 additions and 11 deletions.
23 changes: 15 additions & 8 deletions eclipse-scout-core/src/form/fields/smartfield/ProposalField.js
Expand Up @@ -8,7 +8,7 @@
* Contributors:
* BSI Business Systems Integration AG - initial API and implementation
*/
import {objects, scout, SmartField, strings} from '../../../index';
import {objects, SmartField, strings} from '../../../index';
import $ from 'jquery';

export default class ProposalField extends SmartField {
Expand Down Expand Up @@ -69,7 +69,15 @@ export default class ProposalField extends SmartField {
}

_formatValue(value) {
return scout.nvl(value, '');
if (objects.isNullOrUndefined(value)) {
return '';
}

if (this.lookupRow) {
return this._formatLookupRow(this.lookupRow);
}

return value;
}

_validateValue(value) {
Expand Down Expand Up @@ -161,12 +169,11 @@ export default class ProposalField extends SmartField {
*/
_copyValuesFromField(otherField) {
if (this.lookupRow !== otherField.lookupRow) {
this.setLookupRow(otherField.lookupRow);
this._setLookupRow(otherField.lookupRow); // only set property lookup
}
this.setErrorStatus(otherField.errorStatus);
if (this.value !== otherField.value) {
this.setValue(otherField.value);
}
this.setDisplayText(otherField.displayText);
this.setValue(otherField.value);
}

_acceptInput(sync, searchText, searchTextEmpty, searchTextChanged, selectedLookupRow) {
Expand All @@ -176,8 +183,8 @@ export default class ProposalField extends SmartField {
return;
}

// Do nothing when search text is equals to the text of the current lookup row
if (!selectedLookupRow && this.lookupRow && this.lookupRow.text === searchText) {
// Do nothing when search text did not change and is equals to the text of the current lookup row
if (!searchTextChanged && !selectedLookupRow && this.lookupRow && this.lookupRow.text === searchText) {
$.log.isDebugEnabled() && $.log.debug('(ProposalField#_acceptInput) unchanged: text is equals. Close popup');
this._inputAccepted(false);
return;
Expand Down

0 comments on commit 6f89d63

Please sign in to comment.