@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.
@@ -1577,7 +1577,7 @@ class BaseFormControl {
1577
1577
  });
1578
1578
  // Post trybind se c'è un modello associato ricalcolo l'**EvaluatedModel**
1579
1579
  if (this.Model)
1580
- this.EvaluatedModel = (_a = this.BoundSource.find(t => t.id == this.Model)) === null || _a === void 0 ? void 0 : _a.description;
1580
+ (_a = this.BoundSource.find(t => t.id == this.Model)) === null || _a === void 0 ? void 0 : _a.description;
1581
1581
  }
1582
1582
  }
1583
1583
  /** Valuta il contenuto della variabile BindCheckingGroups */
@@ -1756,8 +1756,9 @@ class BaseFormControl {
1756
1756
  * Non posso tenerlo protected altrimenti posso eseguirlo solo dal .ts e non dall' .html
1757
1757
  */
1758
1758
  changed(forcedValue = null, markForCheck = false) {
1759
- this.propagateChange(forcedValue == null ? this.Model : forcedValue);
1760
- this.inputChange.emit(forcedValue == null ? this.Model : forcedValue);
1759
+ var _a, _b;
1760
+ this.propagateChange(forcedValue == null || forcedValue == "" ? (_a = this.Model) !== null && _a !== void 0 ? _a : "" : forcedValue);
1761
+ this.inputChange.emit(forcedValue == null || forcedValue == "" ? (_b = this.Model) !== null && _b !== void 0 ? _b : "" : forcedValue);
1761
1762
  if (markForCheck)
1762
1763
  this.cdr.markForCheck();
1763
1764
  }
@@ -2128,7 +2129,7 @@ class FormAdaptiveComponent extends BaseFormControl {
2128
2129
  return;
2129
2130
  }
2130
2131
  // Quando filtro la source, se non devo ignorare l'evento devo comunque assicurarmi di impostare il valore selezionato a null
2131
- super.changed("");
2132
+ super.changed(null);
2132
2133
  if (!event && this.MinChars == 0 && !this.SearchFunction) {
2133
2134
  this.FilteredBoundSource = this.BoundSource;
2134
2135
  return;
@@ -2146,6 +2147,7 @@ class FormAdaptiveComponent extends BaseFormControl {
2146
2147
  this.tryBindSourceDisplay();
2147
2148
  // In questo caso è già filtrata dalla SearchFunction
2148
2149
  this.FilteredBoundSource = this.BoundSource;
2150
+ this.removeFilteredSourceOnDescriptionSelection();
2149
2151
  this.cdr.markForCheck();
2150
2152
  });
2151
2153
  }, 400);
@@ -2154,10 +2156,19 @@ class FormAdaptiveComponent extends BaseFormControl {
2154
2156
  this.throttla("filtersource", () => {
2155
2157
  // In questo caso devo filtrare io in memoria
2156
2158
  this.FilteredBoundSource = this.BoundSource.filter(t => (this.CaseSensitive && t.description.includes(event)) || (!this.CaseSensitive && t.description.toLowerCase().includes(event.toLowerCase())));
2159
+ this.removeFilteredSourceOnDescriptionSelection();
2157
2160
  this.cdr.markForCheck();
2158
2161
  }, 100);
2159
2162
  }
2160
2163
  }
2164
+ /** @ignore */
2165
+ removeFilteredSourceOnDescriptionSelection() {
2166
+ if (this.FilteredBoundSource.length == 1 && (this.FilteredBoundSource[0].description === this.Model)) {
2167
+ this.Model = this.BoundSource[0].id;
2168
+ this.EvaluatedModel = this.BoundSource[0].description;
2169
+ this.FilteredBoundSource = [];
2170
+ }
2171
+ }
2161
2172
  /** Metodo richiamato quando viene modificato il modello del campo di input */
2162
2173
  changed() {
2163
2174
  var toEmit = this.getModelToEmit();
@@ -2943,6 +2954,21 @@ class FormAutocompleteComponent extends BaseFormControl {
2943
2954
  this.Model = val ? val.description : value;
2944
2955
  this.EvaluatedModel = this.Model;
2945
2956
  }
2957
+ /**
2958
+ * Quando viene scritto un nuovo valore bisogna controllare se per botta di culo fosse un id, in tal caso dev'essere rieffettuato il bind
2959
+ * per mostrare solo la descrizione nell'autocomplete
2960
+ */
2961
+ evaluateIdResearch() {
2962
+ if (!this.Model)
2963
+ return;
2964
+ this.SearchFunction(this.Model, true).subscribe(t => {
2965
+ if (t && t.length > 0) {
2966
+ this.Source = t;
2967
+ this.tryBindSourceDisplay();
2968
+ setTimeout(() => { this.finalizeValue(this.Model); });
2969
+ }
2970
+ });
2971
+ }
2946
2972
  /**
2947
2973
  * Evento di filtro della sorgente dati in base all'input utente
2948
2974
  *
@@ -2954,7 +2980,7 @@ class FormAutocompleteComponent extends BaseFormControl {
2954
2980
  return;
2955
2981
  }
2956
2982
  // Quando filtro la source, se non devo ignorare l'evento devo comunque assicurarmi di impostare il valore selezionato a null
2957
- super.changed("");
2983
+ super.changed(null);
2958
2984
  if (!event && this.MinChars == 0 && !this.SearchFunction) {
2959
2985
  this.FilteredBoundSource = this.BoundSource;
2960
2986
  return;
@@ -2972,6 +2998,7 @@ class FormAutocompleteComponent extends BaseFormControl {
2972
2998
  this.tryBindSourceDisplay();
2973
2999
  // In questo caso è già filtrata dalla SearchFunction
2974
3000
  this.FilteredBoundSource = this.BoundSource;
3001
+ this.removeFilteredSourceOnDescriptionSelection();
2975
3002
  this.cdr.markForCheck();
2976
3003
  });
2977
3004
  }, 400);
@@ -2980,11 +3007,20 @@ class FormAutocompleteComponent extends BaseFormControl {
2980
3007
  this.throttla("filtersource", () => {
2981
3008
  // In questo caso devo filtrare io in memoria
2982
3009
  this.FilteredBoundSource = this.BoundSource.filter(t => (this.CaseSensitive && t.description.includes(event)) || (!this.CaseSensitive && t.description.toLowerCase().includes(event.toLowerCase())));
3010
+ this.removeFilteredSourceOnDescriptionSelection();
2983
3011
  this.cdr.markForCheck();
2984
3012
  }, 100);
2985
3013
  }
2986
3014
  }
2987
3015
  /** @ignore */
3016
+ removeFilteredSourceOnDescriptionSelection() {
3017
+ if (this.FilteredBoundSource.length == 1 && (this.FilteredBoundSource[0].description === this.Model)) {
3018
+ this.Model = this.BoundSource[0].id;
3019
+ this.EvaluatedModel = this.BoundSource[0].description;
3020
+ this.FilteredBoundSource = [];
3021
+ }
3022
+ }
3023
+ /** @ignore */
2988
3024
  ngOnChanges(changes) {
2989
3025
  var _a;
2990
3026
  let newSource = changes["Source"];
@@ -3017,7 +3053,7 @@ class FormAutocompleteComponent extends BaseFormControl {
3017
3053
  FormAutocompleteComponent.decorators = [
3018
3054
  { type: Component, args: [{
3019
3055
  selector: "form-autocomplete",
3020
- 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>",
3056
+ 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>",
3021
3057
  providers: [{ provide: LocalizationService, useClass: FormAutocompleteComponentLoc }],
3022
3058
  changeDetection: ChangeDetectionStrategy.OnPush
3023
3059
  },] }