How to block retroactive dates in input datetime?

0

I have a form with input of type datetime-local and I need to block the insertion of retroactive dates, how do I do this?

<form name="F1" id="edit-profile" class="form-horizontal" action="" method="post" enctype="multipart/form-data">
  <div class="control-group">
    <label class="form-space control-label" for="lastname">Titulo: </label>
    <input type="text" class="form-space form-control form-margin disable" name="titulo" id="titulo" required="" value="">
    <label class="form-space control-label" for="lastname">Subtitulo: </label>
    <input type="text" class="form-space form-control form-margin" id="subtit" value="" name="subtit" required="">
    <label class="form-space control-label" for="lastname">Caso deseja agendar, insira uma data e hora: </label>
    <input type="datetime-local" class="form-space form-control form-margin" id="agend" value="" name="agend">
    <input type="submit" name="cadastro" value="Enviar" class="btn-post btn">
  </div>
</form>
    
asked by anonymous 18.10.2018 / 16:12

1 answer

0

Try to do this. Note: It does not validate the hours, just the day.

$("#edit-profile").submit(function(e) {

  var agendamento = $("#agend").val().split('T');
  agendamento = new Date(agendamento[0]).setHours(24);
  var hoje = new Date();
  if (agendamento <= hoje) {
    alert('Por favor, insira uma data válida!');
    e.preventDefault();
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><formname="F1" id="edit-profile" class="form-horizontal" action="" method="post" enctype="multipart/form-data">
  <div class="control-group">
    <label class="form-space control-label" for="lastname">Titulo: </label>
    <input type="text" class="form-space form-control form-margin disable" name="titulo" id="titulo" required="" value="">
    <label class="form-space control-label" for="lastname">Subtitulo: </label>
    <input type="text" class="form-space form-control form-margin" id="subtit" value="" name="subtit" required="">
    <label class="form-space control-label" for="lastname">Caso deseja agendar, insira uma data e hora: </label>
    <input type="datetime-local" class="form-space form-control form-margin" id="agend" value="" name="agend">
    <input type="submit" name="cadastro" value="Enviar" class="btn-post btn">
  </div>
</form>
    
19.10.2018 / 15:30