Home > OS >  multiple value input with comma separate
multiple value input with comma separate

Time:11-27

this is the multiple email input box with comma separate
when i tried to delete any email it actually copy the all email and put after the current email

this is the function

 concatCollaborators(){
    if (this.utilService.isValid(this.previousCollaborators) && !this.type.Properties.COLLABORATORS.includes(this.previousCollaborators))
    {
        this.type.Properties.COLLABORATORS = this.previousCollaborators   ','   this.type.Properties.COLLABORATORS;
        this.previousCollaborators = this.type.Properties.COLLABORATORS;
        }
        else{
            this.previousCollaborators = this.type.Properties.COLLABORATORS;
        }
    }

CodePudding user response:

First user should not enter comma separated email address, there are multiple better ways to handle it.

Second, suppose the last letter was a comma, concatCollaborators might be called after you deleted comma, that should not be the case either.

concatCollaborators should not work with strings, you can easily convert them into string[] (email address) by a simple split(',') and then process them, and join them later by join(',') if you really need the string.

CodePudding user response:

now i do this 

  let prev =  this.previousCollaborators?.split(",");
    let newCollab =  this.type.Properties.COLLABORATORS?.split(",");
    for(let i = 0; i < newCollab.length;i  ){  for(let j = 0; j < prev.length; j  )
        if (this.utilService.isValid(this.previousCollaborators) && !prev[j].includes(newCollab[i]) &&  !newCollab[i].includes(prev[j])){ this.type.Properties.COLLABORATORS = this.previousCollaborators   ','   this.type.Properties.COLLABORATORS;  this.previousCollaborators = this.type.Properties.COLLABORATORS;    }
        else { this.previousCollaborators = this.type.Properties.COLLABORATORS;  }
    }
  • Related