Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

validate input with name containing brackets in AngularJS

I have a form input with names containing brackets, e.g.:

<form name="my_form">  
    <input type="text" name="my_form[email]" ng-model="email" ng-class="'mycssclass': my_form.my_form[email].$invalid">
</form>

So, the problem is that Angular is not applying that css class because of the name of my input (my_form[email]), is that the correct notation to reference my input in Angular.

Here's is a plunk: http://plnkr.co/edit/t7PEilV9maNYGnVYnTDc?p=preview

like image 773
PachinSV Avatar asked Aug 13 '14 16:08

PachinSV


1 Answers

The way to reference an input with a name containing brackets is using brackets notation, like this:

my_form['my_form[email]'].$invalid
like image 96
PachinSV Avatar answered Oct 29 '22 17:10

PachinSV