Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

on focus not working for first click #1253

Closed
ramprakash-ravi opened this issue Oct 19, 2015 · 10 comments
Closed

on focus not working for first click #1253

ramprakash-ravi opened this issue Oct 19, 2015 · 10 comments

Comments

@ramprakash-ravi
Copy link

When ui-select is loaded in the page for the first time, it is disabled by default.
But after focusing on other input boxes and focusing on the ui-select it is working as expected.

My HTML:

<ui-select multiple ng-model="newMachine.machine_devices"> <ui-select-match> {{$item.Esn}} </ui-select-match> <ui-select-choices repeat="device in devices | filter:$select.search"> {{device.Esn}} </ui-select-choices> </ui-select>

js:
$scope.devices = [{DeviceID:1,Esn:'SCE112514000145182'},{DeviceID:2,Esn:'SCE112514000145185'}]

@Ampersandman
Copy link

Same problem here but for single select.
Focus on the input (ui-select-focusser) is only set after second click, either directly on the select or document.

@patrickhousley
Copy link
Contributor

I am seeing a very similar issue. Running the latest version of angular-ui-select with angular 1.3.16 was working fine. However, after updating to angular 1.4.5, this issue started occurring. My issue differs slightly...when clicking the select the first time without any value set, the input gains focus. However, if the select already has a value or I click it a second time, the input never gains focus again until I click inside the input field or outside the select field, both of which cause the select to close.

@patrickhousley
Copy link
Contributor

I think I found the issue....if I remove angular-animate 1.4.5 or 1.4.7, it works just fine.

@patrickhousley
Copy link
Contributor

I just found another report of my problem and the fix: #859 (comment).

--edit--

Never mind, the issue @ramprakash-ravi describes is caused when using angular 1.4.4.

patrickhousley added a commit to patrickhousley/ui-select that referenced this issue Nov 6, 2015
Added support for ngAnimate by waiting for animations to complete
before focusing on the search input field. This uses $injector to get a
reference to $animate so that the project is not dependent upon
ngAnimate. Check plunkr http://plnkr.co/edit/G02EbD for a working
example.

This should resolve issues with ngAnimate 1.4.4 and 1.4.5. This should
cover the following issues:

angular-ui#859
angular-ui#1253
@hagis
Copy link

hagis commented Mar 2, 2016

Input field is still not getting focus on first click when using ui-select 0.14.9, angular 1.4.5.

I hacked around this by turning off ALL animations when setting the input focus:

    387       var before = true;
    388       if (ctrl.$animate) {
    389           before = ctrl.$animate.enabled();
    390           ctrl.$animate.enabled(false);
    391       }
    392       $timeout(function () {
    393               ctrl.focusSearchInput(initSearchValue);
    394               if (ctrl.$animate) {
    395                   ctrl.$animate.enabled(before);
    396               }
    397 
    398           });

@patrickhousley
Copy link
Contributor

I can not longer reproduce this issue. My plunker is here. Maybe you can fork it and modify it to your setup. If you are still having the issue, post the plunker back to me and I can take a look.

@hagis
Copy link

hagis commented Mar 7, 2016

Could not instantly reproduce the problem either in the plunker. Will try again later.

@joonask
Copy link

joonask commented Mar 22, 2016

Not focusing on first click. Reproduceble Plunker

@patrickhousley
Copy link
Contributor

@joonask The problem is that you have no items to list out. Thats not to say this is not an issue with the library. However, given that no search value has been entered, users may expect an initial list of values. Try adding the below to the top of your search function.

if (!filterValue || filterValue === '') {
          return names; 
        }

patrickhousley added a commit to patrickhousley/ui-select that referenced this issue Mar 23, 2016
Corrected input focus when ui-select contains no elements. Also corrected a memory leaked caused by event handlers never being removed.

Closes angular-ui#1253
@hagis
Copy link

hagis commented Mar 23, 2016

@patrickhousley, we are using ui-select as a search box, so when the user types something, a backend search call gets made and results are shown. So initially the list of values is always empty.

Good catch on the event leak in your fix.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants