ui-select icon indicating copy to clipboard operation
ui-select copied to clipboard

Leaving the ui-select element does not trigger a "blur" event

Open jdmcnair opened this issue 10 years ago • 32 comments
trafficstars

The inner input element of the ui-select does generate a blur, but this should bubble up and trigger on the ui-select element itself so that it can be used in form validation, etc.

jdmcnair avatar Dec 11 '14 15:12 jdmcnair

+1

surabhi-batra avatar Dec 15 '14 06:12 surabhi-batra

+1 I know is pain in the neck, but this workaround worked for me https://github.com/angular-ui/ui-select/issues/432#issuecomment-65490071

BTW if you need to use (like me) angular 1.2.x use $watch instead of $watchGroup.

jossemarGT avatar Dec 16 '14 00:12 jossemarGT

+1

avrame avatar Apr 13 '15 23:04 avrame

So also in #432, @dimirc added an is-close attribute to the 0.12.0 milestone. That would probably work fairly well for a blur idea. I'm excited to see it in action, personally. I'd rather not have to use a decorator.

jaxspades avatar Apr 21 '15 18:04 jaxspades

Hi, is there any progress made on this issue? thanks :)

xavierfuentes avatar May 19 '15 14:05 xavierfuentes

None of the suggested workarounds seem to work with the latest version of Angular and ui-select.

MiguelMike avatar Jun 08 '15 10:06 MiguelMike

http://plnkr.co/edit/7fSAKmj3pLeeTaid4pMH?p=preview

ghost avatar Aug 05 '15 22:08 ghost

Is there any progress made on this issue?

shanmugam-siva avatar Sep 23 '15 15:09 shanmugam-siva

I have the same problem :(

itchyny avatar Oct 31 '15 16:10 itchyny

still a problem, any progress?

jacobharasimo avatar Nov 03 '15 16:11 jacobharasimo

Still looks like an issue. Going to try ttonyh's workaround.

ghost avatar Nov 11 '15 20:11 ghost

My work around for now was to put a watch on the ng-model field that the ui-select is bound to. Then when the value changes I can handle it how I want.

$scope.$watchGroup(['item.Make', 'item.Model'], function (newValue, oldValue) { if (newValue !== oldValue) { //Do Something because either item.Make or item.Model has changed.
} } Or maybe an OnChange event can be harnessed?
Hope this helps someone out!

joel1618 avatar Nov 20 '15 01:11 joel1618

Depending on how your model is setup, that watcher can help, but it can add performance concerns. This really needs a blur event, not only to keep things performant, but also to work similarly to other input widgets out there today.

jaxspades avatar Dec 02 '15 04:12 jaxspades

+1

mikaeledgren avatar Jan 21 '16 18:01 mikaeledgren

PRs welcome.

wesleycho avatar Mar 27 '16 16:03 wesleycho

I stumbled upon this and thought it would be helpful and although my issue wasn't exactly the same, I too didn't get any trigger on the "blur" event so hopefully this will point you in the right direction.

I needed to bind "click" and "blur" events for a reusable directive. When adding the directive to a <select> box the "change" event did the trick for me:

app.directive('slideTogglePayment', function() {
    return {
        restrict: 'A',
        link: function(scope, element, attrs) {
            element.bind('click change', function() {
                // Code
            });
        }
    };
});

The select box HTML would look like this:

<select ng-model="existingCardId" ng-change="checkoutToggle(orderCart.existingCardId)" slide-toggle-payment="#payment-selection-existing" id="card-existing-selection" ng-options="existingCard as existingCard.NickName for existingCard in existingCards">
    <option value="" ng-bind="selectCardDropDown"></option>
</select>

skashi avatar Apr 20 '16 13:04 skashi

+1

JoyousTanvi avatar Apr 27 '16 19:04 JoyousTanvi

I ended up replacing all of the angular ui-select's with angular- uibootstraps typeahead control because the inability to use the blur event with this control.
https://angular-ui.github.io/bootstrap/

joel1618 avatar Apr 27 '16 19:04 joel1618

+1

kenyus avatar Jun 06 '16 01:06 kenyus

I've come with a workaround to this problem.

app.directive('uiSelectOnClose', function() {
    return {
      require: '^uiSelect', 
      restrict: 'A',
      link: function(scope, element, attrs, $select) {
          if (!attrs.uiSelectOnClose){
              return;
          }
          //get the function from the parent based on the name 
          //parameters are not supported
          var onCloseFn = scope.$parent[attrs.uiSelectOnClose.match(/\w+/g, '')];
          if (!onCloseFn){
              return;
          }

          scope.$watch(function(){return $select.open}, function(newValue,oldValue){
              if ( oldValue == true && newValue == false){
                  onCloseFn();
              }
          });

      }
    };
  });

You can't use the scope to pass the function for this directive because the ui-select directive is already using it, but you can access it from the $parent.

MariusCorneschi avatar Jun 06 '16 14:06 MariusCorneschi

Any progress???

KrakenTyio avatar Jun 22 '16 11:06 KrakenTyio

+1

nivek91 avatar Jun 23 '16 18:06 nivek91

Is this problem resolved or not?

zacyang avatar Jul 12 '16 05:07 zacyang

In my project we use a directive with the ui-select and i show a label animation when the user starts entering text into an inputfield. I suppose it can also be used with a blur event:

scope.$watch(attrs.ngModel, (value) => { if (value) { elem.triggerHandler('input'); } }

PatrickBokhove avatar Jul 21 '16 12:07 PatrickBokhove

Why not bind to the blur event on click of the select?

<ui-select ng-click="c.onClick($select)">

onClick($select) {
   $select.searchInput.on('blur', () => {
       // do stuff
   });
}

cameronlowry avatar Mar 17 '17 10:03 cameronlowry

Maybe somebody can investigate the root cause/ problem and have a good fix in the library? Happy to review the PR.

Thanks

Jefiozie avatar Mar 20 '17 06:03 Jefiozie

There is any fix yet for this issue ?

ady-ghe avatar May 26 '17 13:05 ady-ghe

+1

kamilpp avatar Jul 14 '17 11:07 kamilpp

There are this directive: uis-open-close="onOpenClose(isOpen)"

From Wiki: uis open close.

marcoskubis avatar Aug 04 '17 19:08 marcoskubis

+1

VandendriesscheWard avatar Mar 18 '19 10:03 VandendriesscheWard