2

I'm building a multi-step AngularJS form that adds bootstrap error classes on ng-class. I'm using this tutorial as my base for building the form http://scotch.io/tutorials/javascript/angularjs-multi-step-form-using-ui-router#building-our-angular-app-app.js.

Question: Why are my ng-class css classes not being applied to my form-group wrapper when child fields are invalid? My submit button stays disabled until form fields are correct, but error classes and styling never gets applied.

HTML

<div class="form-group" ng-class="{'has-error has-feedback' : longForm.fullName.$invalid && !longForm.fullName.$pristine}">
  <label class="hidden-xs" for="FullName">Full Name</label>
  <input class="form-control input-lg" type="text" name="FullName" placeholder="Your Full Name" ng-model="longFormData.fullName" required />
</div>
<div class="form-group">
  <button class="btn btn-cta btn-lg btn-block" type="submit" ng-disabled="longForm.$invalid">Next</button>
</div>

1 Answer 1

1

In this particular case it's actually really simple.

You have the name of your input as FullName, but you are referencing it as fullName.

The property names published on the form controller are case sensitive, so just change the case of either:

name="FullName" to name="fullName"

OR

longForm.fullName to longForm.FullName

Sign up to request clarification or add additional context in comments.

3 Comments

I'm also not sure if the class names in ng-class should be specified together like that
@JoseM - They actually can. It's just a JavaScript property name at the end of the day, and spaces in the middle of JavaScript properties is 100% legal :)
@JasonSpence - No problem man :) Admittedly the form stuff is really easy to get mixed up on due to all the repetition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.