Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unfocusing input element reverts value to typed contents (urgent) #241

Closed
alystair opened this issue Jul 25, 2018 · 7 comments · Fixed by #244
Closed

Unfocusing input element reverts value to typed contents (urgent) #241

alystair opened this issue Jul 25, 2018 · 7 comments · Fixed by #244

Comments

@alystair
Copy link

BUG

What is the current behavior?
When deselecting form field, contents revert to what was typed, not autocomplete. See animated sample:
broken

Settings are: hint:false, openOnFocus:true, autoselectOnBlur:true

What is the expected behavior?
Deselecting the field should not revert contents to what was typed... although it would make sense to replace value if you click on the field again to edit choice.

@Haroenv
Copy link
Contributor

Haroenv commented Jul 27, 2018

I don't seem to be able to replicate the problem you have, could you edit the sandbox to show what's going on? https://codesandbox.io/s/5w1wq126pn

@alystair
Copy link
Author

alystair commented Jul 31, 2018

Per your sample there - all you have to do is add event.target.value = ""; to the "selected" event.

I am using the selected contents to generate tags elsewhere on the page, so I'd like to wipe the autocomplete input... however it does not seem to work and refills when defocusing the element.

@Haroenv
Copy link
Contributor

Haroenv commented Aug 1, 2018

Okay, I can replicate it now, one thing that already can be done is changing not to include a displayKey, in which case the input will stay whatever the user typed, and not be replaced by the selected thing. If I understand the flow correctly, when

https://github.com/algolia/autocomplete.js/blob/f0822304e8c0f6ee90ed4db78b0140ac451c3e46/src/autocomplete/input.js#L93-L97
https://github.com/algolia/autocomplete.js/blob/f0822304e8c0f6ee90ed4db78b0140ac451c3e46/src/autocomplete/input.js#L232-L234

is called, it sets the value back to the query on blur. I think it would make sense for your use case to add an option to reset that to empty query instead of the query. Are you interested in contributing that?

@alystair
Copy link
Author

alystair commented Aug 2, 2018

Too busy to do so sadly, working on business logic for the foreseeable future... Is this something that could be done in house? the use case is general enough, although users would have to roll their own tagging mechanism (which is what we've done).

@alystair
Copy link
Author

alystair commented Aug 5, 2018

Thanks @Haroenv - curious how it will be implemented, will there be a new option, will it automagically detect input value being wiped? Just want to prep my code for the patch :)

@Haroenv
Copy link
Contributor

Haroenv commented Aug 6, 2018

I'd add it as a new option @alystair

Haroenv added a commit that referenced this issue Aug 6, 2018
In some use-cases, like when you're using autocomplete to make tags on a page, or using the output in any other way than prefilling the query, you don't want the suggested value to show in the input, but would rather like it to be empty.

Before this PR it was basically impossible to have your input not filled, since it came back on blur and a few different places (see `resetInputValue`

fixes #241
Haroenv added a commit that referenced this issue Aug 7, 2018
…ing (#244)

* feat(clearOnSelected): allow users to clear the input instead of filling

In some use-cases, like when you're using autocomplete to make tags on a page, or using the output in any other way than prefilling the query, you don't want the suggested value to show in the input, but would rather like it to be empty.

Before this PR it was basically impossible to have your input not filled, since it came back on blur and a few different places (see `resetInputValue`

fixes #241

* fix: make sure both query and input are ''

* chore: update test

* chore: test implem of callback too

* chore: more specific test
@Haroenv
Copy link
Contributor

Haroenv commented Aug 8, 2018

@alystair this is now released on the CDN at version 0.31.0

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 a pull request may close this issue.

2 participants