Form validation in select with angular

1

How is the validation of select done using ng-required="true" ? For input I'm putting it like this:

<form name="tarefasForm">
    <input type="text" ng-model="tarefa.solicitante" ng-required="true" name="solicitante-tarefa">
</form

<button ng-click="adicionaTarefa()" type="button"
     ng-disabled="tarefasForm.$invalid">Salvar
</button>

How is it time for a select?

<div class="form-group">
   <label class="" for="orderBy">Tipo</label>
 <select ng-options="tipoTarefa as tipoTarefa.tipo for tipoTarefa in listaTipoTarefa track by tipoTarefa.codigo" ng-model="tarefa.codTipo" class="form-control cb"></select>
</div>
    
asked by anonymous 28.07.2017 / 21:24

1 answer

2

It looks exactly the same.

See an example:

angular.module('app', []);
angular.module('app').controller('mainController', function($scope) {
  $scope.listaTipoTarefa = [
    { codigo: 1, tipo: 'Tipo 1' },
    { codigo: 2, tipo: 'Tipo 2' },
    { codigo: 3, tipo: 'Tipo 3' }
  ];
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><divng-app="app" ng-controller="mainController">
  <form name="tarefasForm">
    <input type="text" ng-model="tarefa.solicitante" ng-required="true" name="solicitante-tarefa">
    <div class="form-group">
      <label class="" for="orderBy">Tipo</label>
      <select ng-required="true"
        ng-options="tipoTarefa as tipoTarefa.tipo for tipoTarefa in listaTipoTarefa track by tipoTarefa.codigo" 
        ng-model="tarefa.codTipo" class="form-control cb"></select>
    </div>
  </form>

  <button ng-click="adicionaTarefa()" type="button"
          ng-disabled="tarefasForm.$invalid">Salvar
  </button>
</div>
    
28.07.2017 / 21:42