Stack Overflow em Português Asked by Grupo Astron on November 23, 2020
Tenho um formulário com um input
do tipo datetime-local
e preciso bloquear a inserção de datas retroativas, como faço isso?
<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>
Tente fazer desta forma. Obs.: Não valida as horas, apenas o dia.
$("#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>
<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>
Answered by Máttheus Spoo on November 23, 2020
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP