skip to Main Content

I want to validate an input field on keypress and then display a popover. I have the blow code:


<form id="coparent">
 <p>This is your last name before you were married <br /> <input type="text" ng-model="comaiden" name="comaiden" id="comaiden" maxlength="70" /><br />
 <span style="font-size:0.8em !important">Number of characters remaining for this field: {{70 - comaiden.length}}</span><br />
 <span class="comaidenError" style="font-size:.9em !important;"></span></p>

Le JavaScript

 $('#comaiden').on("keypress",function (f) {
    if (!firstCapital(f)) {
       $("#comaiden").popover({ title: 'Twitter Bootstrap Popover', 
                        content: "It's so simple to create a tooltop for my website!" });

function firstCapital(e) {
 var inp = String.fromCharCode(e.which);
 if (/[A-Z]/.test(inp[0])) return true;
  else return false;


I would like the popover to appear when the user is entering data. I will also be including an image in the popover. Right now, the popover is appearing on click.



  1. What you are looking for (via your bootply comment example ) is done with jQuery Validate plugin. You can see examples here: How to use Twitter Bootstrap popovers for jQuery validation notifications?

    Login or Signup to reply.
  2. The problem is that your popover code just initializes the popover, but it does not trigger the display of it. You would have to trigger the ‘show’ as well. Something like this:


    I have updated your fiddle to demonstrate:

    Do not that this is just a quick and dirty demo. No need to re-initilaize that popover on each keypress, that would be much better done outside the event handler. And you probably don’t want that flicker of the popover on each keypress either. Not mentioning the hiding and destroying of the popover once the ‘error’ is fixed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top