show popover on input validation in angularjs

徘徊边缘 提交于 2019-12-13 16:57:34

问题


i want to do input validation in angularjs. By showing a bootstrap popover(https://angular-ui.github.io/bootstrap/#/popover) on it when invalid. I cannot figure out how to trigger the popover.

 User name:
   <input type="text" name="userName" ng-model="user.name" popover="m here"  popover-trigger="myForm.userName.$error.required" required>

the [plunker] : http://plnkr.co/edit/PwgquZXzhacvyeKeBc2O?p=preview


回答1:


To trigger a popover using custom conditions you have to use the $tooltipProvider

By default you can trigger the popover only for : mouseenter, mouseleave, click, focus,blur

So you have to define your custom triggers, something like what is shown here : http://plnkr.co/edit/0wEqzz?p=preview

 angular.module('myApp',['ui.bootstrap'])
  .config(['$tooltipProvider', function($tooltipProvider){
    $tooltipProvider.setTriggers({'customEvent': 'customEvent'});
 }]);

angular.module('myApp').controller('myController', ['$scope','$timeout',
  function($scope, $timeout) {
    $scope.fireCustomEvent = function() {
    $timeout(function() {
      $('#tooltipTarget').trigger('customEvent');
    }, 0);
}
}]);


来源:https://stackoverflow.com/questions/29871220/show-popover-on-input-validation-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!