Required html is not working

Asked

Viewed 330 times

0

I am creating a website and I am using angular, and in the only existing input the required is not working, IE, even clicking on the button Submit is sending the empty data to the bank, what can be?

 $scope.adicionaTopico = function (topico) {
     console.log(topico.assunto);
        console.log(topico.descricao);
    $http({
        url: URL + '/topico/cadastrar',
        method: "POST",
        data: {
                'assunto': topico.assunto,
                'idUsuario':1,
                'situacao': 'ATIVO',
                'datahora': new Date(),
                'descricao': topico.descricao,
                'grau':'1'
              }
    })
    .then(function(response) {
          $location.path('/');
    },
    function(response) { // optional
        alert("Erro!!!" + response);
    });
};
<label for="descricao" class="col-sm-1 control-label">Descrição:</label>
    <div class="col-sm-9">
      <input type="text" name="desc" class="form-control" id="desc" placeholder="Seja especifico" ng-model="topico.descricao" required="required">
    </div>

<button type="submit" class="btn btn-info" ng-click="adicionaTopico(topico)">Criar Tópico</button> 
  

  • Note that the required="required" only works with HTML5 the best that Voce should do was to check the server side for example in php

1 answer

1


Place inside a form.

<form>
<label for="descricao" class="col-sm-1 control-label">Descrição:</label>
<div class="col-sm-9">
  <input type="text" name="desc" class="form-control" id="desc" placeholder="Seja especifico" ng-model="topico.descricao" required="required">
</div>

<button type="submit" class="btn btn-info" ng-click="adicionaTopico(topico)">Criar Tópico</button>
</form>

Browser other questions tagged

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