Remove input requirement with anguljar

Asked

Viewed 157 times

0

I have a question with Angularjs, I am making a registration form, and has a certain form that I am doing a validation and has an option to insert multiple phones, it enters the phones clears the input data and goes to a list with angular repeat.

My doubt is, when I enter at least 1 phone, it will remove the mandatory field (required), or set the field as valid.

I tried to use the $setValidity(); but it wasn’t also what I’m doing wrong?

Excerpt from the code I’m using

var $formElem,$formScope;
$formElem = angular.element(formCliente);
$formScope = $formElem.scope();
$formScope.formCliente.telefone.$setValidity('required', false);

1 answer

0

You can use the ng-required , that takes an expression and adds or not the required according to the result of its variable.

<input type="number" data-ng-model="telefoneInput" ng-required="temAlgumTelefoneNaLista"/> 

whereas his $scope.temAlgumTelefoneNaLista = (suaListaDeTelefones.length > 0);

  • Worse than in the structure of the code I made, it needs to use the attribute 'required' even, because it is an automatic validator, I pass the form, and it displays me in a popup the fields of the form divided into tabs, the fields that are mandatory and are not filled in

  • yes, but Voce Voce will go through this 'property' now.. and no longer through the model field linked to its input

Browser other questions tagged

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