bootstrap icon indicating copy to clipboard operation
bootstrap copied to clipboard

Make tooltips appear on disabled input fields

Open michaelhunziker opened this issue 13 years ago • 17 comments

Dear all!

Does anyone know how I could make tooltips appear on disabled input fields?

JSFiddle: http://jsfiddle.net/mhu23/XVnGn/4/

Obviously I need some kind of workaround since ng-disabled prevents all events from firing on disabled items. I just can't figure out a good way...

Thanks for any help!

Cheers Michael

michaelhunziker avatar Sep 17 '13 13:09 michaelhunziker

Unfortunately, browsers don't fire mouse events on disabled input elements, so the tooltip can never fire. That said, an easy workaround is to wrap the disabled input element and put the tooltip on the outer element. e.g.: http://jsfiddle.net/RWZmu/

joshdmiller avatar Sep 17 '13 14:09 joshdmiller

Easy :-)

Thanks a lot for your help!

michaelhunziker avatar Sep 17 '13 14:09 michaelhunziker

Hi @joshdmiller!

I'm still having issues... I wanted to apply your tooltip workaround to a select-element.

See what happens here (problem only occurs in Chrome, IE works): http://jsfiddle.net/sjbsR/7/

Do you have any Idea how I could solve this issue?

Cheers Michael

michaelhunziker avatar Sep 18 '13 13:09 michaelhunziker

Hmm. The mouseenter and mouseleave get fired if you use the bottom edge of the element, but not the top or sides. I get identical behavior in Firefox and Chrome.

Unfortunately, I'm not sure what the specific issue is. A nasty hack with positioning might work though: http://stackoverflow.com/questions/3100319/event-on-a-disabled-input.

Sorry, @michaelhunziker. :-(

joshdmiller avatar Sep 18 '13 14:09 joshdmiller

It seems that if you try to wrap a disabled button and add the tooltip to the outer element, tooltip won't be fired either. http://jsfiddle.net/M6xxk/

andersonvom avatar Sep 25 '13 15:09 andersonvom

Having the same problem. The workaround works fine with an input, but doesn't work with a button.

vrockai avatar Apr 14 '14 14:04 vrockai

This appears to still be an issue when using buttons. Can we reopen this issue, or does a new one need to be created?

Felby avatar May 02 '14 16:05 Felby

@Felby there is one issue about tooltips + disabled fields already, could you please dig it out and comment describing your use case (or better yet - attach a live reproduce scenario with plunker)? Thnx!

pkozlowski-opensource avatar May 02 '14 16:05 pkozlowski-opensource

@pkozlowski-opensource Added to ticket #2059 Thanks.

Felby avatar May 02 '14 16:05 Felby

I worked around the button issue by adding a wrapper, layer full size of the wrapper, then setting z-index of the button underneath the layer when disabled. A bit of a pain, but seems to work fairly well: http://jsfiddle.net/yu10ezkk/1/

jsimpsonjr00 avatar Oct 12 '14 16:10 jsimpsonjr00

Although support for pointer-events isn't perfect yet, you can remove pointer-events from disabled elements so they don't block cursor events from bubbling up to parent items:

[disabled] {
  pointer-events: none;
}

http://jsfiddle.net/KyleMit/27380yvf/

Note: Bootstrap's .btn class will do this automatically

KyleMit avatar Oct 26 '14 23:10 KyleMit

I stumbled across the same issue. I solved it by just setting the css class "disabled" using ng-class and I did the validity check in the Controller.

<button ng-click="save()"
             class="btn btn-default"
             ng-class="{'disabled': myForm.$invalid}"
             popover="This Form is invalid"
             popover-trigger="{{{true: 'mouseenter', false: 'never'}[myForm.$invalid]}}">
        <span>Save</span>
</button>
  $scope.save = function () {
    //check if the form is invalid and abort if it is
    if ($scope.myForm.$invalid) {
      return;
    }
}

kaihenzler avatar Nov 10 '14 09:11 kaihenzler

@kaihenzler that solution won't work for form elements that are not buttons because it is simply cosmetic - it doesn't actually disable the form element.

icfantv avatar Jan 16 '15 21:01 icfantv

Thanks for that solution @KyleMit it works perfectly :)

LuisPalomo avatar Jul 08 '16 10:07 LuisPalomo

The real issue with this is in the prepTriggers function for $uibTooltip provider. For some reason, it works if you DON'T do element.on and instead register the listeners that aren't click with element[0].addEventListener. The problem lies in how jquery lite is handling the events. I can open a PR that fixes this issue.

erikdonohoo avatar Oct 10 '16 20:10 erikdonohoo

Hi guys.. if we use ng-disabled in <select> drop down then if ng-disabled is active then when we mouse hover over the select option then a cross icon displayed. Is it possible to remove that icon while hover over select drop down. Please provide the solution if is it possible.

Thanks, Nishant

nishantpandya avatar Mar 09 '17 14:03 nishantpandya

@nishantpandya select[disabled]:hover {cursor: default;}

adgoncal avatar Mar 15 '17 21:03 adgoncal