Datepicker / Just a few days a week

Asked

Viewed 1,362 times

0

I have a form and the datepicker(id data) field is not working.

Does anyone have any idea why?

Under code:

<?php  
include("connections/configuration.php");

if(isset($_POST['nome'])){
$nome=utf8_decode($_POST['nome']);
$mensagem=utf8_decode($_POST['mensagem']);
$data=utf8_decode($_POST['data']);

if($nome=="" OR $mensagem=="" OR $data==""){
  echo "<script>location.href='index.php';</script>";
}

//cadastra no db a indicacao
$QueryCadastro="Insert Into viplist(nome,mensagem,data)VALUES('$nome','$mensagem','$data')";
  $ExecutaQueryCadastro=mysqli_query($con,$QueryCadastro);

}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Lista Vip</title>
    <link rel="stylesheet" href="template.css">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>


<script src='https://www.google.com/recaptcha/api.js'></script>


<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script>
$(function() {
   $('#data').datepicker({ beforeShowDay:
    function(dt)
    {
       return [dt.getDay() == 1 || dt.getDay() == 3 ? false : true];
    }
 });
});
 </script>


<script>
//Campo 1
jQuery(function($){
        $.datepicker.regional['pt-BR'] = {
                closeText: 'Fechar',
                prevText: '&#x3c;Anterior',
                nextText: 'Pr&oacute;ximo&#x3e;',
                currentText: 'Hoje',
                monthNames: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho',
                'Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
                monthNamesShort: ['Jan','Fev','Mar','Abr','Mai','Jun',
                'Jul','Ago','Set','Out','Nov','Dez'],
                dayNames: ['Domingo','Segunda-feira','Ter&ccedil;a-feira','Quarta-feira','Quinta-feira','Sexta-feira','Sabado'],
                dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],
                dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','Sab'],
                weekHeader: 'Sm',
                dateFormat: 'dd/mm/yy',
                firstDay: 0,
                isRTL: false,
                showMonthAfterYear: false,
        maxwidth: 180,
                yearSuffix: ''};
        $.datepicker.setDefaults($.datepicker.regional['pt-BR']);
});
 $(function() {
    $( "#nascimento" ).datepicker({
      changeMonth: true,
      changeYear: true,
      yearRange: "1900:2020",
      onClose: function (dateText, inst) {
         var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
         var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
         $(this).datepicker('setDate', new Date(year, month, 1));
     }
    });
  });


    $(function() {
    $( "#datepicker2" ).datepicker();
  });

jQuery(function($){
  JQuery(".Maeqst5 input").append('required','false');
  });

      $(function() {
    $( "#datepicker3" ).datepicker();
  });



        $(function() {
    $( "#datepicker4" ).datepicker();
  });


        $(function() {
    $( "#datepicker5" ).datepicker();
  });

//Desabilita o envio ao pressionar Enter
$('#form1').on('keyup keypress', function(e) {
  var keyCode = e.keyCode || e.which;
  if (keyCode === 13) { 
    e.preventDefault();
    return false;
  }
});
</script>



</head>
<body>

<div class="GlobalForm">
<?php 
if($QueryCadastro==true){

?>
<div class="alert alert-success" role="alert">
  <strong>Obrigado!</strong> Seu nome foi adicionado a lista.
</div>

<?php
}
?>

<form action="index.php" method="post">

<div class="form-group">
  <label for="usr">Nome ou Apelido:</label>
  <input type="text" class="form-control" id="nome" name="nome" required="true">
</div>

<div class="form-group">
<label for="usr">Deixe uma mensagem ou informe seus convidados:</label>
    <textarea class="form-control" placeholder="Messagem" name="mensagem"></textarea>
</div>

<div class="form-group">
  <label for="usr">Informe a data que deseja estar na lista vip:</label>
  <input type="text" class="form-control" id="data" name="data" required="true">
</div>

<input type="submit" class="btn btn-info" value="Cadastar"><br/><br/><br/>
<div class="g-recaptcha" data-sitekey="6LdH3xoUAAAAANeEgXuavBhgqKukl3NJfFrz_ZMj"></div>

</form> 
</div>

</body>

  • 1

    What does not work?

  • The data field: <div class="form-group"> <label for="usr">Enter the date you want to be in the vip list:</label> <input type="text" class="form-control" id="data" name="data" required="true"> </div>

  • Any errors in the console? It seems to me that you are adding two vzs to jquery and no datepicker...

  • You want him to bring only those days of the week?

  • The following error appears on the console: at Htmldocument.<Anonymous> ((index):21) at o (jquery.min.js:2) at Object.fireWith (jquery.min.js:2) at Function.ready (jquery.min.js:2) at Htmldocument. B (jquery.min.js:2) * Yes in the case of Sunday to Thursday datepicker only

1 answer

0

I noticed two errors in the datepicker code in question.

First:

return [dt.getDay() == 1 || dt.getDay() == 3 ? false : true];

Placing the expression between brackets means, for Javascript, an array. You need to switch to parentheses, as follows:

return (dt.getDay() == 1 || dt.getDay() == 3 ? false : true);

According to:

If you only want Sunday through Thursday, as you said in the commentary, you need to change your logic:

return (dt.getDay() == 5 || dt.getDay() == 6 ? false : true);

This will enable every day that are not the 5 (Friday) and the 6 (Saturday)

I put it on Jsfiddle for you to see:

https://jsfiddle.net/gga97psd/1/

Browser other questions tagged

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