material icon indicating copy to clipboard operation
material copied to clipboard

ng-focus on md-autocomplete

Open YorffoeG opened this issue 11 years ago • 60 comments

When focus set to md-autocomplete, ng-focus function not call.

YorffoeG avatar Jul 27 '15 09:07 YorffoeG

Same issue applies to ng-blur as well.

mrichar1 avatar Jul 29 '15 13:07 mrichar1

+1 Perhaps the ng-onblur on md-autocomplete have to be $eval on ng-onblur of internal input. Actually the internal input have ng-blur="$mdAutocompleteCtrl.blur()"

Te same for ng-focus.

tolemac avatar Aug 11 '15 18:08 tolemac

Bumping this to 0.12 since more users have been asking for it and it should be relatively straightforward to implement.

jelbourn avatar Aug 18 '15 17:08 jelbourn

+1

A simple modification to the autocompleteDirective and autocomepleteController to expose a directive attribute, something like md-focus and md-blur would allow consumer controllers to operate on those events. as @tolemac pointed out, the internal input already has ng-focus and ng-blur implemented. Hooking in attribute expressions using $parse should be quite simple to implement.

I have a standing PR in https://github.com/angular-ui/ui-select that does something similar: https://github.com/angular-ui/ui-select/pull/1153

RavenHursT avatar Aug 19 '15 22:08 RavenHursT

+1 for md-blur on md-autocomplete

julian-iFactory avatar Aug 21 '15 01:08 julian-iFactory

+1

DeGuitard avatar Aug 29 '15 21:08 DeGuitard

+1

patzick avatar Sep 10 '15 12:09 patzick

+1!

jsenecal avatar Sep 15 '15 15:09 jsenecal

+1

hedder avatar Sep 15 '15 15:09 hedder

+1

friedolinfoerder avatar Sep 18 '15 06:09 friedolinfoerder

+1

SHkreddy avatar Sep 18 '15 20:09 SHkreddy

+1

abeniwal avatar Oct 12 '15 22:10 abeniwal

+1

BenClaveau avatar Oct 24 '15 16:10 BenClaveau

+1

fdomig avatar Oct 30 '15 09:10 fdomig

+1

What I did to still have an "onBlur" event fired:

Created a directive called "autocompleteBlur", the $timeout is important, otherwise the input textbox isn't rendered at that time.

allocateApp.directive('autocompleteBlur', function($timeout){
    return{
        link: function(scope, element, attrs){
            $timeout(clearInputBoxOnBlur, 0);

            function clearInputBoxOnBlur(){
                element.find("#autocomplete-input-id").bind("blur", function(){
                    angular.element(this).val('');
                });
            }
        }
    }
});

Then on the md-autocomplete element, add the newly created directive, and give an id to your input textbox (mine is called "autocomplete-input-id"):

<md-autocomplete
    (...)
    autocomplete-blur
    md-input-id="autocomplete-input-id">
    (...)
</md-autocomplete>

KarmaCop213 avatar Oct 30 '15 11:10 KarmaCop213

+1

cleever avatar Dec 18 '15 13:12 cleever

+1

shichan avatar Dec 19 '15 02:12 shichan

+1

valtersboze avatar Dec 22 '15 19:12 valtersboze

+1

uditalias avatar Jan 03 '16 16:01 uditalias

+1

mwiley63 avatar Jan 21 '16 08:01 mwiley63