@esfaenza/forms-and-validations 15.2.25 → 15.2.27

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.
@@ -3506,7 +3506,7 @@ class FormMultiSelectComponent extends BaseFormControl {
3506
3506
  if (!this.UseKeyValues && !this.UseCommaSeparatedList)
3507
3507
  toEmit = this.Model.map(m => m.id);
3508
3508
  else if (this.UseKeyValues)
3509
- toEmit = this.Model.map(m => ({ id: m.id, description: m.itemName }));
3509
+ toEmit = this.Model.map(m => ({ id: m.id, description: m.description }));
3510
3510
  else if (this.UseCommaSeparatedList)
3511
3511
  toEmit = this.Model.map(m => m.id).join(',');
3512
3512
  this.EvaluatedModel = this.Model.map(t => t.itemName).join(', ');
@@ -3644,6 +3644,9 @@ class FormAutocompleteComponent extends BaseFormControl {
3644
3644
  this.ignoreNextWriteValue = false;
3645
3645
  /** Sorgente Bindata Filtrata in base al contenuto della casella di testo */
3646
3646
  this.FilteredBoundSource = [];
3647
+ this.timer = null;
3648
+ this.maxCallsPerSecond = 4;
3649
+ this.callsDoneThisThreeSeconds = 0;
3647
3650
  //******************** Funzione di throttling per non spammare richieste in caso di animazioni attivate
3648
3651
  //TODO: spostarla in un metodo di utilità (esfaenza/extensions)
3649
3652
  /** @ignore */
@@ -3654,7 +3657,7 @@ class FormAutocompleteComponent extends BaseFormControl {
3654
3657
  if (!value)
3655
3658
  return;
3656
3659
  if (this.SearchFunction) {
3657
- this.SearchFunction(value, true, this.SearchFunctionContext).subscribe(t => {
3660
+ this.doSearchProtected(value, true, this.SearchFunctionContext, (t) => {
3658
3661
  this.Source = t;
3659
3662
  this.tryBindSourceDisplay();
3660
3663
  setTimeout(() => { this.finalizeValue(value); });
@@ -3689,7 +3692,7 @@ class FormAutocompleteComponent extends BaseFormControl {
3689
3692
  let tmpModel = this.Model;
3690
3693
  if (!tmpModel || !this.SearchFunction)
3691
3694
  return;
3692
- this.SearchFunction(tmpModel, true, this.SearchFunctionContext).subscribe(t => {
3695
+ this.doSearchProtected(tmpModel, true, this.SearchFunctionContext, (t) => {
3693
3696
  if (t && t.length > 0) {
3694
3697
  this.Source = t;
3695
3698
  this.tryBindSourceDisplay();
@@ -3725,7 +3728,7 @@ class FormAutocompleteComponent extends BaseFormControl {
3725
3728
  throw "Impossibile filtrare gli elementi senza una funzione di ricerca che restituisca una lista di { id: string, description: string }";
3726
3729
  if (this.SearchFunction) {
3727
3730
  this.throttla("filtersource", () => {
3728
- this.SearchFunction(event, false, this.SearchFunctionContext).subscribe(t => {
3731
+ this.doSearchProtected(event, false, this.SearchFunctionContext, (t) => {
3729
3732
  this.Source = t;
3730
3733
  this.tryBindSourceDisplay();
3731
3734
  // In questo caso è già filtrata dalla SearchFunction
@@ -3744,6 +3747,22 @@ class FormAutocompleteComponent extends BaseFormControl {
3744
3747
  }, 100);
3745
3748
  }
3746
3749
  }
3750
+ // Permetto al massimo 4 chiamate ogni 3 secondi, se nell'arco di 3 secondi ci sono più di 4 chiamate, ignoro le eccedenti
3751
+ doSearchProtected(search, byid, context, onRes) {
3752
+ if (!this.timer) {
3753
+ this.timer = setTimeout(() => {
3754
+ this.callsDoneThisThreeSeconds = 0;
3755
+ clearTimeout(this.timer);
3756
+ this.timer = null;
3757
+ }, 3000);
3758
+ }
3759
+ if (this.callsDoneThisThreeSeconds >= this.maxCallsPerSecond)
3760
+ return;
3761
+ this.callsDoneThisThreeSeconds++;
3762
+ this.SearchFunction(search, byid, context).subscribe(t => {
3763
+ onRes(t);
3764
+ });
3765
+ }
3747
3766
  /** @ignore */
3748
3767
  removeFilteredSourceOnDescriptionSelection() {
3749
3768
  if (this.FilteredBoundSource.length == 1 && (this.FilteredBoundSource[0].description === this.Model) && !this.Multi) {