Hide widget with Angularjs

Asked

Viewed 916 times

0

Hello. I have a routine that checks the elements of a form-group and adds the class has error in the form-validate. Below

var allElements = element.find("input");

for(var i = 0; i < allElements.length; i++) {
var field = angular.element(allElements[i]);
   if(field.parent().parent().hasClass('has-error')){                                              field.parent().parent().removeClass('has-error');
                                    }
                            }

AND THE FORM-GROUP IS LIKE THIS

<div class="form-group">
    <div class="input-group plain-addon">                           
        <div class="input-group-addon"><span class="fa fa-user fa-fw"></span></div>
        <input type="text" ng-model="user.nickname" class="form-control" placeholder="Nome" name="nickname" required>
    </div>
    <span class="help-block"><span class="help-block">Campo obrigatório</span></span>
</div>

I need now to hide the mandatory camp and only show when has error. I’m starting now on Angularjs

2 answers

1

0

I think with css you can solve, you can add a class along with the help-block or use it (depending on your usefulness in the application, this may not be interesting) try something like;

.help-block {
  display: none;
}
.has-error .help-block {
  display: block;
}

If you choose to create a specific class, just replace the help-block with it.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.