bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

typeahead-on-select is not being fired when selecting a item with the mouse and batarang is enabled

Open kdekooter opened this issue 11 years ago • 42 comments

typeahead-on-select is not being fired when selecting an item with the mouse. Tested with angular-bootstrap 0.12.0 and angular 1.3.6

kdekooter avatar Dec 15 '14 10:12 kdekooter

A possible fix could be the following: adding the code that is being executed when an item is selected using the keyboard.

      // Keep reference to click handler to unbind it.
      var dismissClickHandler = function (evt) {
        if (element[0] !== evt.target) {

          // Proposed patch: select the clicked item
          scope.$apply(function () {
            scope.select(scope.activeIdx);
          });

          resetMatches();
          scope.$digest();
        }
      };

kdekooter avatar Dec 15 '14 11:12 kdekooter

I have the same problem and this seems to work great. But I haven't looked through the code enough to know if this is the best place to put it.

nikek avatar Dec 18 '14 16:12 nikek

I encountered the same problem with angular-bootstrap 0.12.0 and angular 1.2.9. kdekooter's fix works for me, but I altered it with the following minor change due to an error happening when deselecting the menu without making any selections

// Proposed patch: select the clicked item
scope.$apply(function () {
    if (scope.activeIdx != -1) {
        scope.select(scope.activeIdx);
    }
});

Can we get an estimate on when this will be fixed? It's a show-stopper for the typeahead directive.

thardy avatar Dec 23 '14 22:12 thardy

I'm not sure where to apply kdekooter/thardy's fix

my attribute on the text input is : typeahead-on-select="onSelect($item,$model,$label)" my controller has function : $scope.onSelect = function ($item, $model, $label) { console.log($item); };

where should i paste the fix to - the controller ? or inside the onSelect function.

EDIT : ok i get it ! Its a fix for typeahead.js

andy4545 avatar Dec 30 '14 09:12 andy4545

@andy4545 glad you found it. Maybe you can submit a PR?

kdekooter avatar Dec 30 '14 10:12 kdekooter

not 100% fix yet...

will submit PR when i get a proper look at it later

andy4545 avatar Dec 30 '14 10:12 andy4545

Just to be clear, this "fix" is not ideal. It's just a hack. If the user clicks elsewhere on the screen (usually with the intent to take no action), whatever item was highlighted will be selected.

What we need is for a real fix to be put in place. A fix that allows a mouse click to select an item in an angular-ui typeahead. We need typeahead to work the way it was intended.

thardy avatar Jan 06 '15 16:01 thardy

To reiterate the versions, mouse clicks aren't selecting an item using ui-bootstrap 0.12.0 and Angular 1.2.27 and 1.2.28. This isn't just an issue with angular 1.3.x.

thardy avatar Jan 08 '15 16:01 thardy

In trying to distill this down into a simple demo to display the problem, my problem with the above versions went away. We are using a nasty combo of jquery mobile plus angular, so I'm not at all surprised. That's the value in trying to distill the problem. Angular 1.2.27 and ui-bootstrap 0.12.0 do not appear to have this problem.

thardy avatar Jan 08 '15 18:01 thardy

Working for me now with angular 1.3.8, angular-bootstrap 0.12.0 and jquery 2.1.3. Thanks @thardy!

kdekooter avatar Jan 09 '15 07:01 kdekooter

Updated my versions last week and just noticed the same combo of versions is also not working for me (angular 1.3.8, ui 0.12, jquery 2.1.3). I'm using the all-in-one ui-bootstrap.tpls.js version.

Selecting by keyboard with enter key does correctly fire typeahead-on-select callback.

Was working previously on angular 1.3.4, ui 0.12, jquery 2.1.1.

Using patch from @thardy to get it working.

bbobrian avatar Jan 19 '15 15:01 bbobrian

Excuse me, what version combination does not have this problem?

skfd avatar Feb 06 '15 03:02 skfd

I'm experiencing this as well. angular v1.2.28, angular-bootstrap v.0.12.0

danielbsig avatar Feb 09 '15 10:02 danielbsig

Same here, angular 1.3.0, angular-bootstrap 0.10

uqcgreen avatar Feb 24 '15 07:02 uqcgreen

Same problem, the mouse click doesn't do anything, using Angular 1.3.2 and Angular-Bootstrap 0.11.2

luiselizondo avatar Feb 27 '15 01:02 luiselizondo

So this isn't perfect but at least it maintains what I believe is supposed to be the default behavior of the typeahead. Beyond what @thardy proposed I only wanted the item to be selected if the user clicks an item in the actual typeahead list:

             // Proposed patch: select the clicked item(only if clicking on the typeahead dropdown)
              if(evt.target.parentElement.id.indexOf("typeahead") != -1) {
                  scope.$apply(function () {
                      if (scope.activeIdx != -1) {
                          scope.select(scope.activeIdx);
                      }
                  });
              }

There is probably a better way to detect this but this is just my quick and dirty proposal.

rbj325 avatar Feb 27 '15 19:02 rbj325

@rbj325 : is this something for people to put into their own code, or is this a change in the library?

danielbsig avatar Feb 28 '15 11:02 danielbsig

@danielbsig This is a change to the library, in the typeahead module. The above code goes into the dismissClickHandler function.

rbj325 avatar Feb 28 '15 16:02 rbj325

I'm experiencing issue with angular 1.2.23 and angular-bootstrap v.0.12

mathiasschaemelhout avatar Mar 23 '15 08:03 mathiasschaemelhout

I am not able to reproduce this here with the current master - in fact, it appears to be working.

There is a possibility that this was fixed. Closing this as it seems invalid currently.

If someone is able to reproduce this based on current master, then post it here and I will reopen the ticket & investigate further.

wesleycho avatar Mar 24 '15 05:03 wesleycho