0

I have a form , which is having few input fields. I want to display error message in popover when user focus out the input field or click on submit button. I created one directive which adds the popover attributes to the input fields. So when user moving out from the input field I will check validation, if validation fails want to show the popover. But when I try to check always I am getting undefined.

Can someone help me on this. My plunker

app.directive("errorTooltip", function($compile, $interpolate, $timeout) {
  return {
    scope: true,
    require: 'ngModel',
    link: function (scope, element, attr, ctrl) { 
          element.attr('popover-trigger', "'show'"); 
          element.attr('popover-placement', 'top');
          element.attr('uib-popover', element.attr("data-info"));

          var blurred = false;
          element.on("blur",function(event){
           blurred = true;
          });
          scope.$watch(function() {
            console.log(ctrl.$name.$invalid); //always comes undefined
            element.triggerHandler('show');
            return ctrl.$name.$invalid
          }, function(invalid) {
          if (!blurred && invalid) { 
              return
              }
             console.log("test")
              //element.toggleClass('has-error', invalid);

        });


    }
  };
});

Thanks in advance .

1 Answer 1

1

Replace the line:

console.log(ctrl.$name.$invalid);

With this:

console.log(ctrl.$invalid);

Updated plunker here.

Sign up to request clarification or add additional context in comments.

1 Comment

do you have any idea how to show the popover when element validation gets failed ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.