@esfaenza/forms-and-validations 11.2.71 → 11.2.74

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.
@@ -1941,7 +1941,7 @@
1941
1941
  });
1942
1942
  // Post trybind se c'è un modello associato ricalcolo l'**EvaluatedModel**
1943
1943
  if (this.Model)
1944
- this.EvaluatedModel = (_a = this.BoundSource.find(function (t) { return t.id == _this.Model; })) === null || _a === void 0 ? void 0 : _a.description;
1944
+ (_a = this.BoundSource.find(function (t) { return t.id == _this.Model; })) === null || _a === void 0 ? void 0 : _a.description;
1945
1945
  }
1946
1946
  };
1947
1947
  /** Valuta il contenuto della variabile BindCheckingGroups */
@@ -2126,8 +2126,9 @@
2126
2126
  BaseFormControl.prototype.changed = function (forcedValue, markForCheck) {
2127
2127
  if (forcedValue === void 0) { forcedValue = null; }
2128
2128
  if (markForCheck === void 0) { markForCheck = false; }
2129
- this.propagateChange(forcedValue == null ? this.Model : forcedValue);
2130
- this.inputChange.emit(forcedValue == null ? this.Model : forcedValue);
2129
+ var _a, _b;
2130
+ this.propagateChange(forcedValue == null || forcedValue == "" ? (_a = this.Model) !== null && _a !== void 0 ? _a : "" : forcedValue);
2131
+ this.inputChange.emit(forcedValue == null || forcedValue == "" ? (_b = this.Model) !== null && _b !== void 0 ? _b : "" : forcedValue);
2131
2132
  if (markForCheck)
2132
2133
  this.cdr.markForCheck();
2133
2134
  };
@@ -2518,7 +2519,7 @@
2518
2519
  return;
2519
2520
  }
2520
2521
  // Quando filtro la source, se non devo ignorare l'evento devo comunque assicurarmi di impostare il valore selezionato a null
2521
- _super.prototype.changed.call(this, "");
2522
+ _super.prototype.changed.call(this, null);
2522
2523
  if (!event && this.MinChars == 0 && !this.SearchFunction) {
2523
2524
  this.FilteredBoundSource = this.BoundSource;
2524
2525
  return;
@@ -2536,6 +2537,7 @@
2536
2537
  _this.tryBindSourceDisplay();
2537
2538
  // In questo caso è già filtrata dalla SearchFunction
2538
2539
  _this.FilteredBoundSource = _this.BoundSource;
2540
+ _this.removeFilteredSourceOnDescriptionSelection();
2539
2541
  _this.cdr.markForCheck();
2540
2542
  });
2541
2543
  }, 400);
@@ -2544,10 +2546,19 @@
2544
2546
  this.throttla("filtersource", function () {
2545
2547
  // In questo caso devo filtrare io in memoria
2546
2548
  _this.FilteredBoundSource = _this.BoundSource.filter(function (t) { return (_this.CaseSensitive && t.description.includes(event)) || (!_this.CaseSensitive && t.description.toLowerCase().includes(event.toLowerCase())); });
2549
+ _this.removeFilteredSourceOnDescriptionSelection();
2547
2550
  _this.cdr.markForCheck();
2548
2551
  }, 100);
2549
2552
  }
2550
2553
  };
2554
+ /** @ignore */
2555
+ FormAdaptiveComponent.prototype.removeFilteredSourceOnDescriptionSelection = function () {
2556
+ if (this.FilteredBoundSource.length == 1 && (this.FilteredBoundSource[0].description === this.Model)) {
2557
+ this.Model = this.BoundSource[0].id;
2558
+ this.EvaluatedModel = this.BoundSource[0].description;
2559
+ this.FilteredBoundSource = [];
2560
+ }
2561
+ };
2551
2562
  /** Metodo richiamato quando viene modificato il modello del campo di input */
2552
2563
  FormAdaptiveComponent.prototype.changed = function () {
2553
2564
  var toEmit = this.getModelToEmit();
@@ -3380,6 +3391,22 @@
3380
3391
  this.Model = val ? val.description : value;
3381
3392
  this.EvaluatedModel = this.Model;
3382
3393
  };
3394
+ /**
3395
+ * Quando viene scritto un nuovo valore bisogna controllare se per botta di culo fosse un id, in tal caso dev'essere rieffettuato il bind
3396
+ * per mostrare solo la descrizione nell'autocomplete
3397
+ */
3398
+ FormAutocompleteComponent.prototype.evaluateIdResearch = function () {
3399
+ var _this = this;
3400
+ if (!this.Model)
3401
+ return;
3402
+ this.SearchFunction(this.Model, true).subscribe(function (t) {
3403
+ if (t && t.length > 0) {
3404
+ _this.Source = t;
3405
+ _this.tryBindSourceDisplay();
3406
+ setTimeout(function () { _this.finalizeValue(_this.Model); });
3407
+ }
3408
+ });
3409
+ };
3383
3410
  /**
3384
3411
  * Evento di filtro della sorgente dati in base all'input utente
3385
3412
  *
@@ -3392,7 +3419,7 @@
3392
3419
  return;
3393
3420
  }
3394
3421
  // Quando filtro la source, se non devo ignorare l'evento devo comunque assicurarmi di impostare il valore selezionato a null
3395
- _super.prototype.changed.call(this, "");
3422
+ _super.prototype.changed.call(this, null);
3396
3423
  if (!event && this.MinChars == 0 && !this.SearchFunction) {
3397
3424
  this.FilteredBoundSource = this.BoundSource;
3398
3425
  return;
@@ -3410,6 +3437,7 @@
3410
3437
  _this.tryBindSourceDisplay();
3411
3438
  // In questo caso è già filtrata dalla SearchFunction
3412
3439
  _this.FilteredBoundSource = _this.BoundSource;
3440
+ _this.removeFilteredSourceOnDescriptionSelection();
3413
3441
  _this.cdr.markForCheck();
3414
3442
  });
3415
3443
  }, 400);
@@ -3418,11 +3446,20 @@
3418
3446
  this.throttla("filtersource", function () {
3419
3447
  // In questo caso devo filtrare io in memoria
3420
3448
  _this.FilteredBoundSource = _this.BoundSource.filter(function (t) { return (_this.CaseSensitive && t.description.includes(event)) || (!_this.CaseSensitive && t.description.toLowerCase().includes(event.toLowerCase())); });
3449
+ _this.removeFilteredSourceOnDescriptionSelection();
3421
3450
  _this.cdr.markForCheck();
3422
3451
  }, 100);
3423
3452
  }
3424
3453
  };
3425
3454
  /** @ignore */
3455
+ FormAutocompleteComponent.prototype.removeFilteredSourceOnDescriptionSelection = function () {
3456
+ if (this.FilteredBoundSource.length == 1 && (this.FilteredBoundSource[0].description === this.Model)) {
3457
+ this.Model = this.BoundSource[0].id;
3458
+ this.EvaluatedModel = this.BoundSource[0].description;
3459
+ this.FilteredBoundSource = [];
3460
+ }
3461
+ };
3462
+ /** @ignore */
3426
3463
  FormAutocompleteComponent.prototype.ngOnChanges = function (changes) {
3427
3464
  var _a;
3428
3465
  var newSource = changes["Source"];
@@ -3459,7 +3496,7 @@
3459
3496
  FormAutocompleteComponent.decorators = [
3460
3497
  { type: core.Component, args: [{
3461
3498
  selector: "form-autocomplete",
3462
- template: "<ng-container *ngIf=\"!FormLayout\">\r\n <ng-container *ngIf=\"DisplayMode && !DisplayModeTemplate\">{{ EvaluatedModel }}</ng-container>\r\n <ng-container *ngIf=\"DisplayMode && DisplayModeTemplate\"><ng-container *ngTemplateOutlet=\"DisplayModeTemplate, context: { $implicit: EvaluatedModel }\"></ng-container></ng-container>\r\n <div [hidden]=\"DisplayMode\"><ng-container *ngTemplateOutlet=\"controlTemplate\"></ng-container></div>\r\n</ng-container>\r\n\r\n<div *ngIf=\"FormLayout\" class=\"form-group row {{FormGroupClass}}\" [class.app-margin-bottom-0]=\"Last\">\r\n <label class=\"col-md-{{LabelColWidth}}\" [class.app-bold]=\"DisplayMode\" [class.m-t-5]=\"!DisplayMode\">{{Label}}{{Required && !DisplayMode ? '*' : ''}}:</label>\r\n <div class=\"col-md-{{InputColWidth}}\">\r\n <ng-container *ngIf=\"DisplayMode && !DisplayModeTemplate\">{{ EvaluatedModel }}</ng-container>\r\n <ng-container *ngIf=\"DisplayMode && DisplayModeTemplate\"><ng-container *ngTemplateOutlet=\"DisplayModeTemplate, context: { $implicit: EvaluatedModel }\"></ng-container></ng-container>\r\n <div [hidden]=\"DisplayMode\"><ng-container *ngTemplateOutlet=\"controlTemplate\"></ng-container></div>\r\n </div>\r\n <div class=\"clearfix\"></div>\r\n</div>\r\n\r\n<ng-template #controlTemplate>\r\n <val-autocomplete [FocusSubject]=\"FocusSubject\" [FieldAppearence]=\"FieldAppearence\" [noValidate]=\"!Validation\"\r\n [submitted]=\"Form?.submitted\"\r\n [forceInvalid]=\"ForcedError\"\r\n [readonly]=\"Readonly\"\r\n [label]=\"SelectLabel\"\r\n type=\"text\"\r\n [(ngModel)]=\"Model\"\r\n [id]=\"GeneratedName\"\r\n name=\"{{GeneratedName}}\"\r\n #validationControl=\"ngModel\"\r\n (inputChange)=\"filterSource($event);\"\r\n (inputFocus)=\"focused($event);\"\r\n (inputFinalized)=\"finalized()\"\r\n (optionChange)=\"changed($event);\"\r\n [placeholder]=\"Required ? ((RequiredPlaceholder != null ? RequiredPlaceholder : ('Select' | localize : lc) + '...')) : Placeholder\"\r\n [validationFailed]=\"FailedValidationMessage\"\r\n [FilteredSource]=\"FilteredBoundSource\"\r\n >\r\n </val-autocomplete>\r\n</ng-template>",
3499
+ template: "<ng-container *ngIf=\"!FormLayout\">\r\n <ng-container *ngIf=\"DisplayMode && !DisplayModeTemplate\">{{ EvaluatedModel }}</ng-container>\r\n <ng-container *ngIf=\"DisplayMode && DisplayModeTemplate\"><ng-container *ngTemplateOutlet=\"DisplayModeTemplate, context: { $implicit: EvaluatedModel }\"></ng-container></ng-container>\r\n <div [hidden]=\"DisplayMode\"><ng-container *ngTemplateOutlet=\"controlTemplate\"></ng-container></div>\r\n</ng-container>\r\n\r\n<div *ngIf=\"FormLayout\" class=\"form-group row {{FormGroupClass}}\" [class.app-margin-bottom-0]=\"Last\">\r\n <label class=\"col-md-{{LabelColWidth}}\" [class.app-bold]=\"DisplayMode\" [class.m-t-5]=\"!DisplayMode\">{{Label}}{{Required && !DisplayMode ? '*' : ''}}:</label>\r\n <div class=\"col-md-{{InputColWidth}}\">\r\n <ng-container *ngIf=\"DisplayMode && !DisplayModeTemplate\">{{ EvaluatedModel }}</ng-container>\r\n <ng-container *ngIf=\"DisplayMode && DisplayModeTemplate\"><ng-container *ngTemplateOutlet=\"DisplayModeTemplate, context: { $implicit: EvaluatedModel }\"></ng-container></ng-container>\r\n <div [hidden]=\"DisplayMode\"><ng-container *ngTemplateOutlet=\"controlTemplate\"></ng-container></div>\r\n </div>\r\n <div class=\"clearfix\"></div>\r\n</div>\r\n\r\n<ng-template #controlTemplate>\r\n <val-autocomplete [FocusSubject]=\"FocusSubject\" [FieldAppearence]=\"FieldAppearence\" [noValidate]=\"!Validation\"\r\n [submitted]=\"Form?.submitted\"\r\n [forceInvalid]=\"ForcedError\"\r\n [readonly]=\"Readonly\"\r\n [label]=\"SelectLabel\"\r\n type=\"text\"\r\n [ngModel]=\"Model\"\r\n (ngModelChange)=\"Model = $event; evaluateIdResearch()\"\r\n [id]=\"GeneratedName\"\r\n name=\"{{GeneratedName}}\"\r\n #validationControl=\"ngModel\"\r\n (inputChange)=\"filterSource($event);\"\r\n (inputFocus)=\"focused($event);\"\r\n (inputFinalized)=\"finalized()\"\r\n (optionChange)=\"changed($event);\"\r\n [placeholder]=\"Required ? ((RequiredPlaceholder != null ? RequiredPlaceholder : ('Select' | localize : lc) + '...')) : Placeholder\"\r\n [validationFailed]=\"FailedValidationMessage\"\r\n [FilteredSource]=\"FilteredBoundSource\"\r\n >\r\n </val-autocomplete>\r\n</ng-template>",
3463
3500
  providers: [{ provide: localizations.LocalizationService, useClass: FormAutocompleteComponentLoc }],
3464
3501
  changeDetection: core.ChangeDetectionStrategy.OnPush
3465
3502
  },] }