Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BOOTSTRAP trigger tooltip on input element only if input val length < n

I would like to show tooltip when input.val().length <= 3 then hide tooltip when > 3 chars

Check this out:

<input type="text" id="nav-search"/>


$('#nav-search').on('keyup',function(){
   var _keys = $(this).val();
   if(_keys.length <= 3){
   $(this).tooltip({'trigger':'focus',position:'right'});
   $(this).trigger('focusin');

   }
  });

it doesn't works obviously :/

like image 527
itsme Avatar asked Jan 16 '23 11:01

itsme


2 Answers

Theoretically, it should work:

$("#nav-search").on("keyup", function() {
    if (this.value.length <= 3) {
        $(this).tooltip("show");
    } else {
        $(this).tooltip("hide");
    }
}).tooltip({
    placement: "right",
    trigger: "focus"
});​

Practically, it works.

DEMO: http://jsfiddle.net/FvxnN/

like image 74
VisioN Avatar answered Jan 23 '23 15:01

VisioN


$('#nav-search').bind('keyup',function(){
   var _keys = $(this).val();
   if(_keys.length <= 3){
   $(this).tooltip({'trigger':'focus',position:'right'});
   $(this).trigger('focusin');

   }else{

  //perform some action
  }
  });
like image 36
StaticVariable Avatar answered Jan 23 '23 14:01

StaticVariable