Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I agree with both of the other two answers but would like to add more</p> <p>I think your main problem is that Bootstrap 3 removed styling based on the <code>:invalid</code> and related pseudo-classes (see <a href="https://github.com/twbs/bootstrap/issues/8093" rel="nofollow noreferrer">here</a> for why). This is where the red outline in bootstrap 2.x came from.</p> <p>Firstly, to fix your plunker you should:</p> <ul> <li>Bootstrap your app with <code>ng-app</code> as Mike says</li> <li>Put your input in a form with <code>novalidate</code></li> <li>Give a model to your input with <code>ng-model</code> so that it can be invalidated (by angular, using classes)</li> <li>Move jQuery script include before bootstrap as it is a requirement of bootstrap.</li> </ul> <p>Now you have a plunker where the correct classes are applied to indicate input validity. You won't yet have styling on these, but they won't depend on your browser's HTML5 form validation, so will work in anything angular supports.</p> <p>To apply styling, you can either use straight CSS and apply it to the <code>ng-valid</code>, <code>ng-invalid</code>, <code>ng-invalid-required</code> etc classes, or you can use the <code>ng-class</code> suggestion from <a href="https://stackoverflow.com/a/17306802/681102">this comment</a> to apply bootstrap's classes when you need them</p> <pre><code>ng-class="{'has-error': formname.inputname.$invalid}" </code></pre> <p>if you have named your input and wrapped it in a control.</p> <p>Updated plunker: <a href="http://plnkr.co/edit/mE3dkG?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/mE3dkG?p=preview</a></p> <hr> <p><strong>Edit</strong></p> <p>I had a go at making a directive for this too. It may be overkill, but this should work wherever you have a <code>form-group</code> class and add an <code>ng-form</code> to the same element</p> <pre><code>.directive('formGroup', function(){ return { restrict: 'C', require: '?form', link: function(scope, element, attrs, formController){ if(!formController) return; scope.$watch(function(){ return formController.$valid; }, function(valid) { if(valid) element.removeClass('has-error'); else element.addClass('has-error'); }); } }; }); </code></pre> <p>Yet another plunker: <a href="http://plnkr.co/edit/UQjRrA?p=preview" rel="nofollow noreferrer">http://plnkr.co/edit/UQjRrA?p=preview</a></p> <p>* The email will not be valid unless it looks like an email</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload