I have a web application where a person can enter their abilities but if there is a bug that allows them to enter blank skills, then I am trying to use ng-required
on input
and ng-disable
on my button to this does not happen, but it is not working.
View
Itworksasfollows,whenIclicktheaddbuttonmyControllergeneratesanewinput
andthenjustwritetheskillandthensave.
ViewCode
<divclass="panel-body">
<div class="row">
<div class="col-sm-6">
<div class="form-group" ng-repeat="item in habilidades">
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" type="button" ng-click="removeHabilidade(item)">
<i class="fa fa-trash-o"></i>
</button>
</span>
<form name="form">
<input class="form-control" type="text" ng-required="true" ng-model="item.nome">
</form>
</div>
</div>
<button type="button" class="btn btn-link" ng-click="addHabilidade()">
<i class="fa fa-plus"></i>
Adicionar
</button>
</div>
</div>
</div>
Function code addHabilidade
$scope.addHabilidade = function() {
$scope.habilidades.push({ nome: '' });
};
So far so good, the problem happens when I put ng-disable
on the Save button.
Save button
<div class="panel-footer">
<button class="btn btn-default" ng-click="salvarHabilidades()" ng-show="!savingHabilidades" ng-disabled="form.$invalid">
<i class="fa fa-save"></i>
Salvar
</button>
It is as if the value of ng-required
was not being passed to the save button, only getting in div
of inputs .
It should be some problem with scope or something like that, because if I put ng-required="form.$invalid"
on the delete button works, they are disabled.