fix(receiver-table): Problem mit automatischer Anredezuweisung für den ersten hinzugefügten Empfänger behoben

- Bedingung in der Funktion `receiver_filter` aktualisiert, um den Indexwert korrekt zu überprüfen.
This commit is contained in:
Developer 02 2024-09-02 10:48:24 +02:00
parent 939ba1bb47
commit e9d686a4c1

View File

@ -1,4 +1,4 @@
import { Component, OnInit, QueryList, ViewChild, ViewChildren } from '@angular/core';
import { Component, OnInit, QueryList, ViewChildren } from '@angular/core';
import { FormsModule, ReactiveFormsModule, FormControl } from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MatTableModule } from '@angular/material/table';
@ -45,17 +45,19 @@ export class ReceiverTableComponent implements OnInit {
receiver_filter: (value: string, options: string[], index?: number) => string[] = (value, options, index) => {
const filterValue = value.toLowerCase();
// set the name if it is used befor
// set the name if it is used before
const name = this.last_used_name[value];
if (name && index)
if (name && index != null && index != undefined) {
this.receiverData.at(index)!.name = name
}
// !!! do not allow email duplication !!!
var similarMails = this.receiver_mails.filter(m => m.toLocaleLowerCase() === value.toLocaleLowerCase() && m !== value)
if (similarMails.length > 0 && index != undefined) {
this.receiverInputs[index].text = similarMails[0];
}
console.log(this.receiverInputs.length + " - " + index)
// if added into last row
if (value.length > 0 && (this.receiverInputs.at(-1)?.lenght ?? 0) > 0) {
this.receiverData.at(-1)!.accessCode = generateAccessCode();
@ -64,7 +66,7 @@ export class ReceiverTableComponent implements OnInit {
}
// delete the row with out mail
else if (value.length === 0 && this.receiverInputs.length - 1 !== index) {
if ( this.receiverInputs.length > 1 && this.receiverInputs[index!]?.lenght === 0) {
if (this.receiverInputs.length > 1 && this.receiverInputs[index!]?.lenght === 0) {
this.receiverData.splice(index!, 1);
this.update();
}