javascript - ng-pattern wrong or not doesn't allow tooltip to be triggered -


i'm using ng-pattern="/^[0-9]{9}$/" in input field render follow:

<input      type="text"      id="company_taxid"      ng-model="company.taxid"      required="required"      class="input ng-scope ng-valid-maxlength ng-valid-minlength ng-dirty ng-valid-required ng-invalid ng-invalid-pattern"      style="width:485px;"      ng-minlength="9"      maxlength="9"      ng-maxlength="9"      ng-pattern="/^[0-9]{9}$/"      placeholder="ej: 458965879"      tooltip="ej: 458965879"      wv-def="ej: 458965879"      tooltip-trigger="focus"      tooltip-placement="right"      wv-cur=""      wv-err="este valor debería ser un número válido."      wv-req="este campo es requerido"      wv-min="este valor debería tener exactamente 9 caracteres"      wv-max="este valor debería tener exactamente 9 caracteres" > 

if pattern fails, example if wrote letter instead numbers message "este valor debería ser un número válido" should trigger it's not working , can't find problem is. pattern wrong? wrong there?

this directive handle tooltip trigger:

app.directive('validated', function() {     return {         restrict: 'a',         link: function(scope, element, attrs) {              element.keyup(function(){                 parent = $('.tooltip');                 target = parent.find('.tooltip-inner');                  if( element.hasclass('ng-invalid-required') ){                     target.html(attrs.wvreq);                     attrs.wvcur = attrs.wvreq;                     parent.addclass('error');                 }                 else if( element.hasclass('ng-invalid-email') ){                     target.html(attrs.wveml);                        attrs.wvcur = attrs.wveml;                     parent.addclass('error');                    }                 else if (element.hasclass('ng-invalid-name-exists')) {                     target.html(attrs.wvnam);                     attrs.wvcur = attrs.wvnam;                     parent.addclass('error');                 }                 else if( element.hasclass('ng-invalid-minlength') ){                     target.html(attrs.wvmin);                        attrs.wvcur = attrs.wvmin;                     parent.addclass('error');                    }                 else if( element.hasclass('ng-invalid-maxlength') ){                     target.html(attrs.wvmax);                        attrs.wvcur = attrs.wvmax;                     parent.addclass('error');                 }                 else if( element.hasclass('ng-invalid') ){                     target.html(attrs.wverr);                     attrs.wvcur = attrs.wverr;                     parent.addclass('error');                    }                 else{                     target.html(attrs.wvdef);                     attrs.wvcur = attrs.wvdef;                     parent.removeclass('error');                     }             });              element.focus(function(){                 //attrs.title = attrs.wvcur;                  settimeout(function(){                     parent = $('.tooltip');                     target = parent.find('.tooltip-inner');                      target.html((attrs.wvcur != "" ? attrs.wvcur : attrs.wvdef));                     if( attrs.wvcur != attrs.wvdef && attrs.wvcur != "" )                         parent.addclass('error');                 },5);             });         }     }; }); 

ps: i'm using twitter bootstrap tooltip this

the ng-model attribute not optional (as can seen here). assign it, needs exist in scope. need supply scope controller valid variable reference in ng-model.

here working example. can see if remove or otherwise invalidate scope variable assigned ng-model stops working.

this solve issue, in general suggest achieve you're trying closer shown in angular's docs.

edit: here working version of code: demo

however, can't set element attributes using attr trying do. have use element. , doesn't have tooltip element (you can add it). again, strongly advise take here , maybe @ angular tutorials , examples, , try rewrite code in style.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -