-
Notifications
You must be signed in to change notification settings - Fork 610
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
Update input text on autocomplete option highlight #16897
Comments
@jimf Thanks for very detailed explanation. So how does jQuery UI autocomplete widget handles this case? Does it have option, event or something else? |
@vlazar this is the default behavior. Afaict, there is actually no direct way to disable it. |
Personally I'm leaning towards having additional event and implementing your use case in userland.
It will be trivial to add new event here: https://github.com/LeaVerou/awesomplete/blob/gh-pages/awesomplete.js#L70 It looks like hitting escape is the only case when the currently highlighted choice should be reverted on But then, of course, it's an API and obvious question would be wether we should add one more event or not. Also, I'm a bit worried about meaningful event name. If we'll add, say |
Okay, I've hacked together a proof-of-concept that does what I want using the existing API (only tested in Chrome): https://jsfiddle.net/jimfitz/wgk9a32c/. I'm not in love with the timeout stuff, but I don't think there's an alternative without updating the library. The cancel-event approach would allow me to consolidate PS: Possibly worth a secondary PR, but it seems the close event gets fired, even when the dialog isn't open. Is this known/intentional? I had to work around it in the fiddle. I'd imagine |
Another option worth considering is adding an argument to the cancel event that would expose the cancel method. The following example would suffice for my needs: $.fire(this.input, "awesomplete-close", { escape: true }); However, it may be beneficial to encode the "close reason" for all the places where the dialog closes, so one could differentiate between escape/blur/confirm etc. directly in the event callback. |
I've played a bit with your example at https://jsfiddle.net/jimfitz/wgk9a32c/. I don't know if this is something you care about, but jQueryUI example at http://jqueryui.com/autocomplete/ does not revert selected text on blur event in addition to keydown esc, while yours does. Here is how I would probably implement this https://jsfiddle.net/yaufeLwn/1/. It also handles blur/esc similarly to jQueryUI. Is it simple enough for not to add new features to Awesomplete? Or maybe there are other good reasons to support add new event or "close reason" so that library users can simplify their code? EDIT: Updated URL to fiddle. |
Yes, sorry. I fixed that behavior in my own code but didn't bother to update the fiddle. The behavior you describe/implemented is what I'm after.
Nice! I got so caught up trying to do this with the given Awesomplete events that it didn't even occur to me to just use a keydown. This is much nicer.
At this point I am satisfied. Thank you for your time! 🍻 |
Yep, exactly. I was trying to do the same thing initially. It's like trying to do something X-way immediately shuts off the brain for other options :) |
I like the proposed behavior. |
Ok, here is the list where
What would be the good names for parameter value in those cases? We probably don't want to attach semantic meaning to this parameter. For example, one may want similar behavior on |
|
👍 from me. I'd be happy to implement if we're in agreement. |
Sure, as long as you update the docs too! |
Can you do the tests too, please? |
Just reviewed the list of cases when For example, I agree with this concern:
Also, does |
Will do.
Of course!
Sounds good. I'll make that change in a separate PR.
Combining makes sense to me, but I don't have strong feelings. |
Emit a reason when firing `awesomplete-close` events to provide transparency to attached event listeners regarding the circumstance in which the close was triggered. Reasons include `blur`, `esc`, `submit`, `select`, and `nomatches`. Closes LeaVerou#16897
Emit a reason when firing `awesomplete-close` events to provide transparency to attached event listeners regarding the circumstance in which the close was triggered. Reasons include `blur`, `esc`, `submit`, `select`, and `nomatches`. Closes LeaVerou#16897
Emit a reason when firing `awesomplete-close` events to provide transparency to attached event listeners regarding the circumstance in which the close was triggered. Reasons include `blur`, `esc`, `submit`, `select`, and `nomatches`. Closes LeaVerou#16897
Is this new behavior released yet? I can't tell but I don't think it is? |
Also: I used the enhancement from @vlazar fiddle (https://jsfiddle.net/yaufeLwn/1/). But this behavior does conflict with 'autoFirst:true'. I kinda need both features to work. But if you use them together, you lose the ability to backspace and type something else. |
@vlazar I meant the proposed behavior described by jimf in the original post concerning : I just got the latest zip and this feature didn't seem to be included, so I used the fiddle you made to enhance it. About my other issue that it conflicts with the setting autoFirst:true -> I realised that's to be expected. |
No, the proposed behavior is not supported out of the box, but is easy to implement. This issue however led to #16899 with additional info available on events, so it should be even easier o implement than in original fiddle. |
Just want to start out by saying that I'd be happy to implement any work that might come out of this issue. I'm more looking for a general +1 on the idea, as well as hash out what the api might look like. With that out of the way...
Goal: I'm looking to replace a jQuery-UI based autocomplete implementation with Awesomplete. However, for feature parity, I need the input text to update as I navigate through autocomplete choices. More concretely:
I'm fairly confident that this can all be achieved with the existing API. Live-updating the input text is fairly trivial with the
awesomplete-highlight
event, and the original value can be cached onawesomplete-open
. The hacky part comes with the escape functionality, as the code currently makes no distinction between pressing escape and any of the other methods of closing. I might be able to do something withsetTimeout
/clearTimeout
, but it's definitely not ideal, hence this issue.So open questions:
The text was updated successfully, but these errors were encountered: