Skip to content

When adding any token from onTokenRemoved callback method, the added token also gets removed #378

Description

@maheshwariaanchal

Hello,
When I remove any token by clicking cross image of the token, the callback method "onTokenRemoved" is called. Its working fine till here. Now in that method(onTokenRemoved) I am adding another token using method "MyCompletionView.addObjectAsync(list.get(0));"
This is the last line of that method. No more lines are there to be executed.
Whenever the token is added callbacks goes to "onTokenAdded" and after that the callback automatically again goes to "OnTokenRemoved" method, it executes from the very first line of that method for the newly added token and the newly added token is removed.

Please help. Its pretty urgent.
Thanks in advance.

Activity

  1. mgod commented on Feb 25, 2019

    @mgod
    Contributor

    Can you give me some more details on what you're actually trying to accomplish in the UI? Are you able to reproduce the issue with the sample project?

    I can only imaging this happening if you are adding the same object that got removed, but I can't figure out how to reproduce this myself.

  2. maheshwariaanchal commented on Feb 26, 2019

    @maheshwariaanchal
    Author

    Hi,
    Thanks for the reply. Actually what I am trying to do is, I have a list of items and they can be multiselected or deselected.
    So when I select some items from the list I show only the first selected item in completion view and write (+5 more, depending on the number of items selected) in front of that item. Now if the item which is shown in completion view is deselected by the user, I remove that item from the completion view and add one selected item from the remaining selected item list.

    So while doing so the callback method "onTokenRemoved" is called when removing the item. At the same time when the call arrives in "onTokenRemoved" method, I add one token from the remaining selected items using the method MyCompletionView.addObjectSync(list.get(0)).
    Now the callback method "onTokenAdded" is called. And from there "onTokenRemoved" is automatically for the newly added item.

    However If I add token after some delay (around 3 sec), its working fine and the callback is not going to "onTokenRemoved" for the added token.

    I have not reproduced it on the sample project.

    Thanks.

  3. mgod commented on Feb 26, 2019

    @mgod
    Contributor

    It seems like that should work without the delay, but I might also try a different approach. I haven't updated the docs for this yet, but I don't expect these interfaces to change at this point. I would override shouldIgnoreToken and return true if the user is selecting an item in the list that is already in the view. When this happens, the onTokenIgnored listener callback will fire and I would then remove the token from the view and add the new random token. This might avoid the callback cycle you're currently stuck in.

  4. maheshwariaanchal commented on Feb 28, 2019

    @maheshwariaanchal
    Author

    Thanks again. Sorry for the late reply. I didn't exactly get what you are trying to say. But I am still working on it. I have provided some delay when adding token and its working fine. I am still looking for some workaround. Please let me know if you get any solution for this.
    Thanks

  5. mgod commented on Mar 9, 2019

    @mgod
    Contributor

    I've updated the docs for version 3.0.0, which might make my suggestion more clear.

  6. mgod commented on Mar 9, 2019

    @mgod
    Contributor

    Actually, on looking this over, I think this might be resolved by 3.0.0. Can you try it and let me know if you're still seeing the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions