DevExpress / DevExtreme

HTML5 JavaScript Component Suite for Responsive Web Development
https://js.devexpress.com/
Other
1.82k stars 596 forks source link

when entering duplicate tags in dx-tag-box it removed the values #12343

Closed RezaRahmati closed 4 years ago

RezaRahmati commented 4 years ago

Steps to Reproduce:

  1. Open https://codesandbox.io/s/overview-devextreme-tag-box-wmeb5?fontsize=14&hidenavigation=1&theme=dark
  2. type test in tag box, confirm it shows the test
  3. type test again

Results You Received:

Both test tags are removed (also both are removed from valueChange event argument)

Results You Expected:

It shows both test, or if it doesn't let duplicates should keep one of them

Environment Details:

Devexterme: 19.2.6

devexterme-tag-box-issue

Bykiev commented 4 years ago

@RezaRahmati, hi!

Seems to be a really bug for me, but you can change the logic of onCustomItemCreating callback function to prevent adding duplicate values.

RezaRahmati commented 4 years ago

@Bykiev can you please clone and modify my code, (as I tried before not able to do that)

Bykiev commented 4 years ago

@RezaRahmati, here is a sample of implementation of onCustomItemCreating function. I tried it, but it still resets all selected values, but prevents adding duplicate values to dataSource...

onCustomItemCreating(args) {
    let newValue = args.text;

    if (this.editableProducts.indexOf(newValue) == -1) {
      this.editableProducts.unshift(newValue);
      args.customItem = newValue;
    }
  }
RezaRahmati commented 4 years ago

@Bykiev yes, exactly, I tried it before too, just wanted to be sure we are on same page.

Bykiev commented 4 years ago

@RezaRahmati, it seems behaviour in https://github.com/DevExpress/DevExtreme/issues/12343#issuecomment-604974145 is correct, just try to type in already selected item, select it and it'll be removed from selection

RezaRahmati commented 4 years ago

@Bykiev I tried, still same behavior, tags will be removed check my updated sandbox https://codesandbox.io/s/overview-devextreme-tag-box-wmeb5?fontsize=14&hidenavigation=1&theme=dark

Bykiev commented 4 years ago

@RezaRahmati, not all tags will be removed, but only duplicated. I belive this behaviour is correct, check this demo with search mode and try to select item multiple times and it'll be remove from selection. But let's wait for offical response from DevExpress team

artem-kurchenko commented 4 years ago

Hi all,

TagBox doesn't support duplicated tags. You can implement unique keys for each item if you wish to have the same display text for them. Please test the following example: https://codesandbox.io/s/overview-devextreme-tag-box-9xtz3

Alternatively, you need to validate values before applying them. Please refer to DxTagBox generates duplicate items when acceptCustomValue equals true where we discussed this task.

RezaRahmati commented 4 years ago

@artem-kurchenko Hi Artem, I don't know why I missed your response.

What I want is if user enters an item that already exists, don't do anything, right now it removes it, even with checking in onCustomItemCreating

How can I implement this behavior?

seanoz commented 3 years ago

@artem-kurchenko Hi Artem, I don't know why I missed your response.

What I want is if user enters an item that already exists, don't do anything, right now it removes it, even with checking in onCustomItemCreating

How can I implement this behavior?

Did you ever manage to figure this out? Banging my head against the wall right now, trying to do the same.

RezaRahmati commented 3 years ago

@artem-kurchenko Hi Artem, I don't know why I missed your response. What I want is if user enters an item that already exists, don't do anything, right now it removes it, even with checking in onCustomItemCreating How can I implement this behavior?

Did you ever manage to figure this out? Banging my head against the wall right now, trying to do the same.

No, unfortunately

gabbyfreed-co commented 3 years ago

Is there any update on this ticket? Having the same issue as described in the original ticket submission. If two duplicate custom items are added, I want the tagbox to only keep one of the tags, not remove them both entirely...

stevecurrey commented 3 years ago

I am also facing the same issue. If someone enters a custom tag twice, why are both values removed? It should only remove the duplicate.