gch1p / bootstrap-5-autocomplete

autocomplete/typeahead js plugin for bootstrap v5
104 stars 36 forks source link

onClick handling problem #7

Closed mrekin closed 2 years ago

mrekin commented 3 years ago

Hi! Looks like problem exist with 'click' event handling.

116        let dataLabel = e.target.getAttribute('data-label');
117        let dataValue = e.target.getAttribute('data-value');

Then you click on highlighted text in drop-down menu target has not button element but <span class=""text-primary"..> which does not have such attributes.

I solved this issue for myself by using currentTarget

116        let dataLabel = e.currentTarget.getAttribute('data-label');
117        let dataValue = e.currentTarget.getAttribute('data-value');

but im not sure if it best solution (cause i'm not js developer) :) So I don't make pool request.

p/s also i add possibility to autocomplete more than one word (but it is 'duck' code, which replaces last entrance of 'lookup' variable, not whole input value - better solution to replace text before coursor position)

dugi07 commented 3 years ago

I got similar bug. When i chosed/clicked highlighted text i don't recive value of the label. When i clicked on row - not exacly on text (Place 2 on picture) i got correct value. Is there any solution to that problem ?

obraz

jquery-3.3.1 bootstrap-select1.14.0 bootstrap-5.0.1

mrekin commented 3 years ago

@dugi07 I solved as described below (in my fork), but not sure if it best way.

dugi07 commented 3 years ago

Thx @mrekin. I'm thinking i had an oldest version before last pull request (it was 6 days ago). I tried to find line: let dataLabel = e.currentTarget.getAttribute('data-label'); but i can't. I got only line 117. I overlooked latest version... Ur suggestion really solve the problem in the last version. Thx a lot agan ! What about pull request ? Wait for some js developer to commit changes.

AgentSmith0 commented 2 years ago

Thanks @mrekin! Your solution helped me. I also created a PR here: https://github.com/gch1p/bootstrap-5-autocomplete/pull/17