Problems with required in select in angularJs

0

Personal I have the following code:

<div class="form-group col-lg-6 col-xs-12 " style="    margin-bottom: 0px;">
    <label style="padding-top: 4px;margin-bottom: 3px;">Grupo</label>
    <select class="form-control " ng-options="grupo as grupo.descricao for grupo in vm.produto.listaGrupo" ng-model="vm.grupoSelecionado" required>
        <option value="">Escolha uma opção</option>
    </select>
</div>
<div class="form-group col-lg-6 col-xs-12 " style="    margin-bottom:5px;">
    <label style="padding-top: 4px;margin-bottom: 3px;">Tipo</label>
    <select class="form-control " ng-options="subGrupo.codigoTabItemSubGrupoId as subGrupo.descricao for subGrupo in vm.grupoSelecionado.tabItemSubGrupo" ng-model="vm.subGrupoSelecionado" required>
        <option value="">Escolha uma opção</option>
    </select>
</div>

My problem is that the two fields are as required, but when giving them empty, the operation happens normally, but the right thing would be to stop the operation because they are empty. All fields with required are with expected behavior, just those 2 that are select that are not doing validation correctly, if someone can help me I thank.

    
asked by anonymous 11.04.2018 / 16:36

1 answer

0

Use ng-required to check if the model value is empty or not. In the case: ng-required="vm.grupoSelecionado" e ng-required="vm.subGrupoSelecionado" , it's worth remembering that ng-required is based on expressions.

    
12.04.2018 / 18:28