Skip to content

Conversation

@matthew-sycle
Copy link

We have a use case where we can have many people with the same name, i.e. search string. This causes a problem in the part of the code which checks if the last search string is the same as the current search string, because it mean't we couldn't trigger the suggestions by entering the same search string.

This change adds an optional setting, which skips this "short-circuit" logic, and instead do the return in the _suggest method, where we have access to check the $scope.selected_index. If the user has selected an index from the suggestions, we short-circuit the suggestion operation, immediately after resetting that $scope.selected_index to 0

@hakib
Copy link
Owner

hakib commented Apr 1, 2016

Hey @matthew-sycle, I don't think I understand the use case.

Lets say you have 10 options and 5 of them are 'Dave'. The user enters 'Da' in the box, _suggest is invoked with 'Da' and you return the 5 dave's as possible suggestions. At this point the user can either select on of the daves, add another digit 'Dav' to refine the search or remove a digit 'D'. So far so good.

In what scenario is it possible for the user to enter the same input to the suggestion box and get different results?

@matthew-sycle
Copy link
Author

Say my input is "Bob". 10 options are displayed, and I pick the first one, which sets my ngModel, and hides the suggestions. I want a different "Bob", so I add or remove a character to trigger the suggest() again. Then I can pick a different "Bob".

The problem is that the search string is unchanged after a debounce, even though the content had been modified. So I couldn't re-trigger suggest() in order to "pick a different Bob".

@matthew-sycle
Copy link
Author

To contrast from your example, I want to re-trigger the debounced suggest() with the identical search string "Bob", and not "Bo" or "Bobb", for example.

@hakib
Copy link
Owner

hakib commented Apr 1, 2016

Then I can pick a different "Bob".

I'm confused. Why do you need to trigger suggest to select a different "bob"? You can just select a different bob from the list. Note that if you have similar options in the list you are not expected to return different suggestions if I delete "b" and add it again. Select is triggered regardless of the value so if the user selected a bob in a different index you will get the select cb.

I want to re-trigger the debounced suggest() with the identical search

Unless the underlying data is changing when would you get different results here?

@matthew-sycle
Copy link
Author

The results could have changed (e.g. waiting for results in API to update), but I just want to be able to get the list of suggestions for "Bob" to display again, by quickly changing the string and changing it back again. Now that the suggestions are showing again, I can pick a different suggestion from the (same) results.

@hakib
Copy link
Owner

hakib commented Apr 1, 2016

The results could have changed (e.g. waiting for results in API to update)

If you load your suggestions from the server you need to return a promise from the suggest function. The box will appear only after the promise is resolves - this is already handled by the package.

I still don't fully understand the use case here. I can't think of any situation where (given a stable set of results) a term can yield different suggestions.

If the underlying data is changing while the box is displayed then it should be handled by notifying the promise (maybe) not by triggering changes in the model value.

@matthew-sycle
Copy link
Author

As I said, the search results may not have changed, I just want to be able to get those same suggestions (or maybe new ones) to display again, by re-triggering the suggest with the same search value as before. This bit of code was stopping this from happening:

// Prevent suggestion cycle when the value is the last value selected.                   // Prevent suggestion cycle when the value is the last value selected.
// When selecting from the menu the ng-model is updated and this watch                    // When selecting from the menu the ng-model is updated and this watch
// is triggered. This causes another suggestion cycle that will provide as                    // is triggered. This causes another suggestion cycle that will provide as
// suggestion the value that is currently selected - this is unnecessary.                     // suggestion the value that is currently selected - this is unnecessary.
 -            if (nv === last_selected_value)        
                return;

As it is, it will normally re-trigger on a search string change, but it would NOT re-trigger for the same search string, which is what I need.

@udevnl
Copy link

udevnl commented Sep 13, 2016

@matthew-sycle - I recognize your point. I am experiencing exactly this issue. I think the desire we have can be captured in a more generic sense:

What I want is to use MassAutoComplete in two different ways:

  1. To select a UNIQUE value from a list of suggestions that is entered into the input field.
    With this approach, normally, the input field is overwritten by the unique value you selected.
    In this scenario it would not make sense to show the suggestions if the checkbox as long as the input field has this value.
  2. To select a non-UNIQUE value...
    With this approach when selecting a suggestion, the value entered into the combobox is not unique as multiple suggestions lead to the same value.
    In this scenario you want to re-show the suggestions whenever the user so much as touches the input field. This is currently impossible due to the if statement you pointed out.

A non-unique value for suggestions is one of my use-cases:
I use MassAutoComplete to search through some items.
Whenever the user selects an item, I change another part of the screen.
For the input field, I want to KEEP the text the user entered and NOT replace it by the value of the item. So I simply set the value of all items to the current model value in the suggest function.
This way, the search query that the user it typing is not lost / overwritten.

But as said, I have run into the same issue that an unchanged value does not re-show the suggestions.

@hakib - do you recognize scenario 2 is a valid use-case?

@hakib
Copy link
Owner

hakib commented Sep 14, 2016

@udevnl Hey, if I understand your use case correctly it can be summed up to being able to show the suggest box when an input that already have text gets focus (e.g without typing)?

@udevnl
Copy link

udevnl commented Oct 5, 2016

@hakib Sorry for the later reply - Regarding what you said:
Almost. If you always show the suggest box on focus this will feel awkward and always block the view beneath it while you may not be interested in the suggested.

More nuanced:
Show the suggest box when the user starts typing again - even if the value does not change. So adding or removing a white space should also show the suggestions.

@hakib
Copy link
Owner

hakib commented Oct 8, 2016

@udevnl - not sure i understand.

Lets take the first input in the example page. If i enter new I get suggestions (New York, New Hampshire...). If after new I add space, new<space>, the suggestions are still relevant so they are displayed.

Can you give a simpler example of what you are trying to achieve?

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

Successfully merging this pull request may close these issues.

3 participants