Fix spurious duplicate values being sent by selectInput #2187
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2162. I described the root cause in my comment.
The fix I made is to explicitly detect this condition in the selectize input binding, and suppress the event that (temporarily) sets the value to
""
. So the selectize input binding does cause an"NY"
event to be raised when you backspace, but now it's correctly squelched by the client side dupe-detecting logic.Testing notes
Here is a slightly improved reprex of the original issue. Without this fix, you will see
"NY"
printed at first; and if you click into the select box and backspace, you'll see"NY"
printed again. With this fix, you'll only see"NY"
printed the first time. In no case should you be able to get it to show an empty string for the value.This example adds a "Please choose one" prompt, which causes
""
to now be a valid state. Both before and after this fix, backspacing should cause""
to be printed at the console, and "Please choose one" should appear in the select box.This example is like the first one except it uses
selectizeInput
instead ofselectInput
; the defaults are slightly different, in thatselectizeInput
allows you to have nothing selected. So with and without the fix, you should see backspace cause""
to be printed at the console, and clicking focus away from the select box control should leave it empty.