Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS validation and field name with square brackets

I'm following this tutorial http://scotch.io/tutorials/javascript/angularjs-form-validation but I have form fields with square brackets ( for example company_bundle_task[timeStart][date] - rendered by Symfony2 ) and validation on those fields doesn't work, for example this:

<span class="help-block" ng-show="company_bundle_task.company_bundle_task[timeStart][date].$invalid">Required</span>

or

<span class="help-block" ng-show="company_bundle_task.company_bundle_task[timeStart][date].$error.required">Required</span>

they are never shown, even though those fields are invalid/empty/etc.

like image 722
mmmm Avatar asked Jul 07 '26 00:07

mmmm


1 Answers

You have to escape your name in quotes, since a.example is equivalent of a['example'] you can write:

<span class="help-block" ng-show="company_bundle_task['company_bundle_task[timeStart][date]'].$error.required">Required</span>
like image 159
pdem Avatar answered Jul 08 '26 15:07

pdem