Skip to content
This repository was archived by the owner on Nov 25, 2020. It is now read-only.

autocomplete: clear active item after selection #84

Merged
merged 1 commit into from
Sep 24, 2014
Merged

Conversation

humanchimp
Copy link
Contributor

After an item is chosen, we should clear the selected item in the list view. The implementation is a little weird. I noticed that code was pretty old that I was editing :). This fixes a bug where the same item will be selected multiple times when it shouldn't be.

@@ -47,3 +47,6 @@ module.exports = class KDAutoCompleteListView extends KDListView
active.index = i
break
active

setActiveItem: (target) ->
item.active = item is target for item in @items
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think itemDataPath option should play a part here if it is set to a non-null value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation is designed to be symmetrical to the getter. Can you explain your idea?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Identity of a list item is determined by itemDataPath when an object is passed as an argument to a method of list view. I thought keeping the same behavior in similar views would be consistent semantically. Equality operator is not always enough to determine same object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sinan can you advise about this? I am not sure I understand about the item data path. In the case of autocomplete, i believe that the is operator will be sufficient to compare list items.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have two different copies of the very same object then is operator returns false and comparing argument of the function against list data misses the item you want to be processed.

This is what we have experienced with removing an item from list view. Data was fetched from two different sources. Identical two objects stored in different places in the memory. is operator was returning false. So, implementation improved to take data path into account if it's provided to compare identity of the argument and item in the list.

This is the case I wanted to be covered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but I don't think that can happen for this method, which is just going to set the active item for the autocomplete view, and not for list views in general. If you want me to make this change, can you please open a PR against my fork that implements your suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I can find time to do that then I will open another pull request. This shouldn't hold off the pull request. I'll be merging this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I would make the change myself, but I wasn't able to grok your suggestion. I don't understand how I should check the identity of the object by the item data path, which is just a string.

@humanchimp
Copy link
Contributor Author

@szkl can we merge this please?

@szkl
Copy link
Member

szkl commented Sep 24, 2014

Right away.

szkl pushed a commit that referenced this pull request Sep 24, 2014
autocomplete: clear active item after selection
@szkl szkl merged commit 02bb46e into master Sep 24, 2014
@szkl szkl deleted the autocomplete-fix branch September 24, 2014 18:42
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants