osl-base-extended 16.3.1 → 16.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2212,6 +2212,8 @@ class OslAutocomplete extends baseComponent {
2212
2212
  manualEntry = false;
2213
2213
  /** True while the model holds text the user is typing rather than a picked option (manualEntry only). */
2214
2214
  isManualText = false;
2215
+ /** Search text the current Api datasource was loaded for — lets blur tell whether the results are current. */
2216
+ lastSearchedText = null;
2215
2217
  modelChange = new EventEmitter();
2216
2218
  changeEv = new EventEmitter();
2217
2219
  /** Full objects behind the current chip selection (chips mode only). */
@@ -2314,6 +2316,7 @@ class OslAutocomplete extends baseComponent {
2314
2316
  if (!res.isSuccessful)
2315
2317
  return;
2316
2318
  this.datasource = res?.result && Array.isArray(res?.result) ? res.result : res?.result?.data;
2319
+ this.lastSearchedText = value;
2317
2320
  this.datasourceChange.emit(this.datasource);
2318
2321
  this.filteredItems = this.datasource;
2319
2322
  this.cdr.markForCheck();
@@ -2450,7 +2453,7 @@ class OslAutocomplete extends baseComponent {
2450
2453
  // cleared text and datasource had only 1 item.
2451
2454
  // If no selection was made, clear the typed text.
2452
2455
  if (this.isManualText) {
2453
- this.commitManualEntry();
2456
+ void this.commitManualEntry();
2454
2457
  }
2455
2458
  else if (this._model === null || this._model === undefined) {
2456
2459
  this.inputValue = '';
@@ -2459,13 +2462,36 @@ class OslAutocomplete extends baseComponent {
2459
2462
  this.cdr.markForCheck();
2460
2463
  }
2461
2464
  /** manualEntry: finalize typed text on blur — pick the option it exactly names, otherwise keep the trimmed text as the model. */
2462
- commitManualEntry() {
2465
+ async commitManualEntry() {
2463
2466
  const text = this.inputValue.trim();
2464
- const match = text
2465
- ? this.datasource?.find((item) => this.getDisplay(item)?.toLowerCase() === text.toLowerCase())
2466
- : undefined;
2467
+ let match = this.findExactOption(text, this.datasource);
2468
+ const resultsAreStale = this.lastSearchedText?.trim() !== text;
2469
+ if (!match && text && this.searchType === 'Api' && this.methodName && this.service && resultsAreStale) {
2470
+ // Blurred before the debounced search returned for this text — look it up so an
2471
+ // exact option is still picked instead of being kept as manual text.
2472
+ let res;
2473
+ try {
2474
+ res = await this.service[this.methodName]({ searchValue: text, apiBody: this.apiBody });
2475
+ }
2476
+ catch {
2477
+ res = undefined;
2478
+ }
2479
+ // Picked, cleared or retyped while the lookup was in flight — nothing left to commit here.
2480
+ if (!this.isManualText || this.inputValue.trim() !== text)
2481
+ return;
2482
+ if (res?.isSuccessful) {
2483
+ const results = Array.isArray(res.result) ? res.result : res.result?.data;
2484
+ match = this.findExactOption(text, results);
2485
+ if (match) {
2486
+ this.datasource = results;
2487
+ this.datasourceChange.emit(this.datasource);
2488
+ this.filteredItems = this.datasource;
2489
+ }
2490
+ }
2491
+ }
2467
2492
  if (match) {
2468
2493
  this.selectItem(match);
2494
+ this.cdr.markForCheck();
2469
2495
  return;
2470
2496
  }
2471
2497
  this.inputValue = text;
@@ -2474,6 +2500,15 @@ class OslAutocomplete extends baseComponent {
2474
2500
  this.isManualText = false;
2475
2501
  this.modelChange.emit(this._model);
2476
2502
  this.changeEv.emit(this._model);
2503
+ this.cdr.markForCheck();
2504
+ }
2505
+ /** Option whose display text (displayFn or displayField) equals the typed text, ignoring case and surrounding spaces. */
2506
+ findExactOption(text, list) {
2507
+ if (!text || !Array.isArray(list))
2508
+ return undefined;
2509
+ const target = text.toLowerCase();
2510
+ const same = (v) => v !== null && v !== undefined && String(v).trim().toLowerCase() === target;
2511
+ return list.find((item) => same(this.getDisplay(item)) || (!!this.displayField && same(item?.[this.displayField])));
2477
2512
  }
2478
2513
  clearValue(event) {
2479
2514
  event?.stopPropagation();
@@ -2500,6 +2535,10 @@ class OslAutocomplete extends baseComponent {
2500
2535
  this.inputControl.setValue(display, { emitEvent: false });
2501
2536
  this._model = value;
2502
2537
  this.isManualText = false;
2538
+ // Keep the object behind the model current — otherwise the [(model)] echo of this
2539
+ // pick resets the datasource to the previous object and the display can't resolve.
2540
+ if (this._object)
2541
+ this._object = item;
2503
2542
  this.modelChange.emit(value);
2504
2543
  this.changeEv.emit(value);
2505
2544
  this.showDropdown = false;