Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Bootstrap tooltip on focus when an angular input has an error

This example is taken from angularjs's docs

<form name="myForm" ng-controller="Ctrl">
  userType: <input name="input" ng-model="userType" required>
  <span class="error" ng-show="myForm.input.$error.required">Required!</span>
</form>

I want to achieve the same behavior but with a Bootstrap tooltip. I've looked at the Angular UI-Bootstraped project (http://angular-ui.github.io/bootstrap/) but can't figure out how to do this.

Something like:

<input type="text" value="Click me!"
    tooltip="See? Now click away..." 
    tooltip-trigger="focus"
    tooltip-placement="right"
    tooltip-enabled="myForm.input.$error.required"   <--- pseudo code
    />
like image 493
Cotten Avatar asked Aug 07 '13 15:08

Cotten


1 Answers

I've tried several ways, looks like you only can modify source code from angular-bootstrap to get a proper solution. But. There is a 'hacky' solution, maybe it'll help you or even that's what you needed(examples from angular-bootstrap and angular-input combined):

<form name="myForm" class="my-form">
  userType: <input style="width: 50px;" name="input" ng-model="userType" required value="Click me!" tooltip="{{myForm.$valid ? '' : 'See? Now click away...'}}"  tooltip-trigger="focus" tooltip-placement="right" class="form-control">
  <span class="error" ng-show="myForm.input.$error.required">Required!</span><br>
  <tt>userType = {{userType}}</tt><br>
  <tt>myForm.input.$valid = {{myForm.input.$valid}}</tt><br>
  <tt>myForm.input.$error = {{myForm.input.$error}}</tt><br>
  <tt>myForm.$valid = {{myForm.$valid}}</tt><br>
  <tt>myForm.$error.required = {{!!myForm.$error.required}}</tt><br>
 </form>

same in plunker.

basically here you just remove text from tooltip and it hides.

like image 60
Rasalom Avatar answered Nov 16 '22 12:11

Rasalom