angularjs - Directive for input element with error assistance span elements -


I am trying to write an instruction to verify the input for the IP address.

I'm very much like this boiler plate code on the web:

  & lt; Label & gt; IP address 1: & lt; / Label & gt; & Lt; Input ng-model = "formData.ip1" Required name = "ip1" type = "text" placeholder = 'xxx.xxx.xxx.xxx' ng-pattern = "/ ^ (\ d {1,3} \.) {3} (\ d {1,3}) $ / "& gt; & Lt; span ng-show = "myForm.ip1. $ Error.required" style = "color: red" & gt; * & Lt; / Span & gt; & Lt; Span ng-show = "myForm.ip1. $ Dirty & amp; myForm.ip1. $ Invalid" style = "color: red" & gt; This is an invalid IP. & Lt; / Span & gt;   

Since it requires dozens of places, and when verification rules and the way errors are indicated, the possibility will change, I would like to use a command like this: & lt; Label & gt; IP address A: & lt; / Labels & gt; & Lt; input ng-model = "formData.ipa" is required my-ip-validator & gt;

myIpValidator will add command attributes (such as ng-pattern) and additional elements (such as spans)

I have tried in several ways with one of my latest compilation instructions It was as if I started a plunker (see update below)

I did not know how to get the name of the form for use in NG-see. Also, the required sections in the resulting input element were not later added as angular, such as ng-pristine, ng-invalid, etc.

How can I do this? I'm open to fix problems with either this instruction or a completely different approach.

Update: The above planer was wrong. It was an old man working on an update which I will post soon.

Update 2: I did a few things that worked on Flickr, losing the Factor to the $ collection. And, the second part was getting the name of the form from some domicile inspection. Now I will clear it and I will improve it. But if anyone has other suggestions, then I am open to learning. This was my first instruction.

I am answering my question Yes, it can be done I was close to the compilation approach I need to fix some small things, it was not working on the planker because I was not compiling $ in directing.

  var inputname = element.attr ("name"), and I did not know how to get the form and input name.  

foundForm = false, ancestors = element.parent (); While (! FoundForm & Ancestors) {If (angular uppercase (ancestor .prop ("tagname")) == "FORM") {foundForm = true; Var FORMAN = Ancestors Reuters ("name"); } And (ancestor = ancestors. Parent ();}}

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -