1
I have a web application, where a person can enter their skills but if there’s a bug that allows them to enter blank skills, then I’m trying to use the ng-required
in the input
and the ng-disable
on my button so it doesn’t happen, but it’s not working.
View
It works like this, when I click on the add button mine Controller generates a new input
and then just write the skill and then save.
View code
<div class="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 the 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’s like the value of ng-required
wasn’t being passed to the save button, just staying in the div
of inputs.
Must be some problem with Scope or something, because if I put the ng-required="form.$invalid"
on delete button(recycle bin) works, they are disabled.
I didn’t quite understand, that would be: http://jsfiddle.net/sinkz/Lvc0u55v/659/ ?
– DiegoAugusto
Yes, the goal is that, but it’s not running ng-disable. It seems the value of $invalid being passed when ng-required for false is not reaching ng-disable from the Save button
– Gustavo Moreira
What the
name
of your form?– developer033
The name of my FORM is " form ". A very generic name
– Gustavo Moreira
when there is only 1 works? When it generates more than 1 they must be getting the same name. You already debugged to see the value that is in the form. $invalid? puts "{form. $invalid}}" in your html and see how it looks
– André Vicente