I have the situation: in the table below, when I click on "edit", it displays the form with the necessary fields (even with a new "cancel" button). So far everything is working well. The problem is that when saving, the form should disappear (ng-hide) and resubmit normal data. Just below is an excerpt from JS. I understand that I can not change the editing after saving.
Table with phones
<form name="telefoneEdit">
<table class="table table-hover">
<thead>
<tr>
<th width="30%">Telefone</th>
<th width="20%">Ramal</th>
<th width="40%">Descrição</th>
<th width="10%"></th>
</tr>
</thead>
<tbody ng-repeat="telefone in clienteCtrl.cliente.ClienteTelefone" ng-form="tel" ng-init="editing = false">
<tr ng-show="!editing">
<td>{{telefone.tel}}</td>
<td>{{telefone.ramal}}</td>
<td>{{telefone.descricao}}</td>
<td class="text-center">
<a ng-click="editing = true" class="btn btn-default btn-xs"><i class="icon-pencil2"></i></a>
</td>
</tr>
<tr ng-show="editing">
<td>
<div class="col-md-4">
<input ng-model="telefone.ddd" type="number" name="ddd" max="99" ng-maxlength="2" class="form-control input-sm"></input>
<label class="error" ng-show="tel.ddd.$invalid">Campo inválido</label>
<label class="error" ng-show="erros.ddd">{{erros.ddd[0]}}</label>
</div>
<div class="col-md-8">
<input type="number" name="telefone" ng-model="telefone.telefone" class="form-control input-sm" ng-minlength="8" required></input>
<label class="error" ng-show="tel.telefone.$invalid">Campo inválido</label>
</div>
</td>
<td>
<input ng-model="telefone.ramal" class="form-control input-sm"></input>
</td>
<td>
<input ng-model="telefone.descricao" class="form-control input-sm"></input>
</td>
<td class="text-center">
<button class="btn btn-default btn-xs" type="button" ng-click="editTelefone(telefone)"><i class="icon-disk"></i></button>
<a ng-click="editing = false" class="btn btn-default btn-xs"><i class="icon-close"></i></a>
</td>
<input type="hidden" ng-model="telefone.id" />
</tr>
</tbody>
</table>
</form>
Excerpt from JS that should work
$scope.editTelefone = function(telefone) {
var erros = {};
var _data = {};
_data.ClienteTelefone = telefone;
self.editing = false;
$http
.post('api/cliente_telefones/edit.json',_data)
.success(function(data){
if(data.erros) {
$scope.erros = data.erros;
}
else {
self.telefone = telefone;
$scope.erros = false;
$scope.editing = false;
}
})
}
Everything works correctly, I just can not hide the form again.
Illustrative images
Tableinitsoriginal/initialstate
EditingForm
Result after submitting the edit form