angularjs - how can I apply has-error to a single input inside form-group, where multiple inputs exist -
im using angularjs , $invalid
add .has-error
form group.. problem 1 of form groups has multiple inputs in it, side side..
<div class="form-group"> <div class="col-sm-6"> <label for="location">location</label> <select class="form-control input-lg" name="location" ng-model="newrack.location" ng-options="location location.name location in locations" placeholder="locations" required></select> </div> <div class="col-sm-6"> <label for="name">rack size</label> <input type="number" class="form-control input-lg" name="size" ng-model="newrack.size" min="1" max="48" required> </div> </div>
validation similar this, include additional validations size element well.
ng-class="{ 'has-error': rackform.location.$invalid && rackform.location.$dirty }"
if name=size
becomes invalid, stands .has-error
applied entire form group, , can confusing end user. there way either
- apply .has-error specific input
- rearrange form layout bit each input in own form group, yet still retain side side look.
the way create form-group each input element. also, believe don't need inner <div class="col-sm-6">
since can join class form-group , same results.
<div class="form-group col-sm-6" ng-class="{ 'has-error': rackform.location.$invalid && rackform.location.$dirty }"> <label for="location">location</label> <select class="form-control input-lg" name="location" ng-model="newrack.location" ng-options="location location.name location in locations" placeholder="locations" required></select> </div> <div class="form-group col-sm-6" ng-class="{ 'has-error': rackform.size.$invalid && rackform.size.$dirty }"> <label for="name">rack size</label> <input type="number" class="form-control input-lg" name="size" ng-model="newrack.size" min="1" max="48" required> </div>
let me know if helped
Comments
Post a Comment