Midnight Guest
Midnight Guest

Reputation: 1910

accessing input with special characters in name in angular

I have inputs with dynamically assigned names. As a result I have input names like

name="Athlete/Guardian_firstName"

For inputs it's fine, but validation doesn't work since this record

medForm.Athlete/Guardian_firstName.$invalid

is invalid for angular's ng-class due to the slash "/". (medForm is form's name). Are there any other way to access inputs from form in angular, so inputs with any special characters will work?

<div class="form-group" ng-class="{ 'has-error': medForm.Athlete/Guardian_firstName.$invalid }">
  <label for="firstName" class="col-md-3 control-label">First Name</label>
  <div class="col-md-9">
    <input type="text" class="form-control" id="firstName" name="Athlete/Guardian_firstName" required ng-model="firstName">
  </div>
</div>

Upvotes: 1

Views: 1001

Answers (1)

karaxuna
karaxuna

Reputation: 26940

Try this way:

medForm['Athlete/Guardian_firstName'].$invalid

Upvotes: 5

Related Questions