Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addTag adding a object instead a string #809

Closed
williangd opened this issue Sep 12, 2018 · 5 comments
Closed

addTag adding a object instead a string #809

williangd opened this issue Sep 12, 2018 · 5 comments
Assignees

Comments

@williangd
Copy link

Describe the bug
I don't using bindValue and bindLabel properties, but when the tag is added, it gets the format: { "label": "dsadas" }

<ng-select [items]="simpleItems" [(ngModel)]="selectedSimpleItem" [multiple]="true" [addTag]="true"></ng-select>

This problem does not occur in versions 1.x or 2.0.0.

Expected behavior
When you do not use binds, the value added is just a string.

@varnastadeus
Copy link
Member

Which version you are using? Also create reproducible example

@williangd
Copy link
Author

williangd commented Sep 14, 2018

I have the "problem" with any version > 2.0.0.

Example: https://stackblitz.com/edit/ng-select-hzcdzr

@MarkDoggen
Copy link

I have this as well. As a temporary fix I used the addTag method as follows:

[addTag]="addTag"

and in component.ts:

addTag(tag: string) {
    /* https://github.com/ng-select/ng-select/issues/809 */
    return tag;
}

@varnastadeus varnastadeus self-assigned this Sep 20, 2018
jakemdunn pushed a commit to jakemdunn/ng-select that referenced this issue Oct 16, 2018
NickMele pushed a commit to NickMele/ng-select that referenced this issue Apr 12, 2019
@mohit-nirwan
Copy link

I have this as well. As a temporary fix I used the addTag method as follows:

[addTag]="addTag.bind(this)"

and in component.ts:

addTag(tag: string) {
    /* https://github.com/ng-select/ng-select/issues/809 */
    return tag;
}

This would be required for it to work

@HongLinh97
Copy link

I have this as well. As a temporary fix I used the addTag method as follows:
[addTag]="addTag.bind(this)"
and in component.ts:

addTag(tag: string) {
    /* https://github.com/ng-select/ng-select/issues/809 */
    return tag;
}

This would be required for it to work

-Can I ask how to customize the label and value of newly tag? Because when using addTag(tag: string) function above, the label and value is the same. I need to customize the value (increasing number for example) but still keep the label from insert

-I also try:

addTag(tag: string) {
     let newOpt : NgOption = {
       label: tag+ "-new",
        value: tag,
    }
   return newOpt;
 }

The error is: get the label from newOpt, but the value is still an object {label: 'awsd-new', value: 'awsd'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants