lekoala / bootstrap5-autocomplete

Autocomplete for Bootstrap 5 (and 4!)
MIT License
87 stars 16 forks source link

Feature idea: Optional Fill in button #33

Closed AgentSmith0 closed 11 months ago

AgentSmith0 commented 1 year ago

What about adding an optional "Fill in" button next to each item in the autocomplete list, that just sets the input value without calling the selection callback. Example: grafik

lekoala commented 1 year ago

what would be the use case for this ?

AgentSmith0 commented 1 year ago

To explain it with the example of the URL autocompletion: The autocomplete list only shows some recommendations. If one of them doesn't fix exactly, it would be useful to fill it into the text field, but without submitting the value immediately. Then you can edit it (e.g. append some path to a URL) without having to write the full URL. This improves user experience a lot. If you like, I will try to suggest some HTML changes, that will add this button to the list and you could help with the logic...

AgentSmith0 commented 1 year ago

Here is a quick prototype: Autocomplete item HTML before:

<li role="presentation">
<a id="ac-menu-2-0" class="dropdown-item text-truncate" data-value="0" data-label="test" tabindex="-1" role="menuitem" href="#">test</a>
</li>

HTML after (only added a few classes to the li element and added a new a element as child):

<li class="d-flex justify-content-between align-items-center" role="presentation">
<a id="ac-menu-2-0" class="dropdown-item text-truncate" data-value="0" data-label="test" tabindex="-1" role="menuitem" href="#">test</a>
<a href="#" class="btn border-0"><i class="fa-solid fa-arrow-up-left"></i></a>
</li>
lekoala commented 1 year ago

mhh i see. yes that makes a lot of sense. i have no spare time to implement this but if anyone wants to make a PR i would be happy to review it :)

lekoala commented 11 months ago

@AgentSmith0 it's pushed on master, it looks like this

image
AgentSmith0 commented 11 months ago

@lekoala Thanks for implementing this, the demo works really fine. But I have seen one problem: If you click the fill in button and have the highlightTyped option on, the input gets also HTML code (the mark element) from the item.

AgentSmith0 commented 11 months ago

I was able to fix this issue by changing in line 865 this._searchInput.value = label; to this._searchInput.value = item.label;.

AgentSmith0 commented 11 months ago

Another small improvement could be to keep the autocomplete dialog opened after the fill in button is pressed.

lekoala commented 11 months ago

@AgentSmith0 pushed on master. indeed if you want to keep editing the focus should stay there

AgentSmith0 commented 11 months ago

Looks good now, thank you!

AgentSmith0 commented 11 months ago

@lekoala Could you please release the new version with the minified file?