Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

885
Visualizações
Disable past date in FullCalendar for dateClick

Those who still looking for a solution on how to disable past date click on Dateclick event on FullCalendar. can try see solution below, if any of the reader had other idea can post other solution below. It would be much better if there is another easy way. The more solution, the better it would be.

about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

It's possible to improve on your string-manipulation of dates, by doing a simple comparison as follows:

dateClick: function (info) {
  var clickedDate = getDateWithoutTime(info.date);
  var nowDate = getDateWithoutTime(new Date())
  if (clickedDate >= nowDate) alert("Future date");
  else alert("Past date");
}

It is helped by this function:

//get date without the time of day
function getDateWithoutTime(dt)
{
  dt.setHours(0,0,0,0);
  return dt;
}

Demo: https://codepen.io/ADyson82/pen/ZErwJGx


One other option to achieve the same goal is to use the validRange functionality. This lets you dynamically set a start date, before which all dates are disabled:

validRange: function (nowDate) {
  return {
    start: nowDate
  };
},

Demo: https://codepen.io/ADyson82/pen/VwQgWJO

The slight downside of this though is that it also hides any events which occur before the current date - you may not want this.


Therefore, another alternative is to use selectAllow to restrict where the user can select. Note that this relies on you using the select callback rather than dateClick - but that should not be a big problem.

selectAllow: function (info) {
  return (info.start >= getDateWithoutTime(new Date()));
}

Demo: https://codepen.io/ADyson82/pen/VwQgzZJ

about 4 years ago · Santiago Gelvez Relatório

0

Below is just my current solution to disable past date on FullCalendar. Any idea or improvement would be appreciate to improve the code below.

dateClick: function(e) {

    // Get Today
    var dt = calendar.getDate();
    var year = dt.getFullYear();
    var month = dt.getMonth() + 1;
    var day = dt.getDate();

    if(month < 9){
        month = '0'+month;
    }

    if(day < 9){    
        day = '0'+day;
    }
    
    var today = year + '-' + month + '-' + day;

    // Get Selected Date
    var check = e.dateStr;
                
    let A = today.toString();
    let B = check.toString();

    alert('Date A: ' + A );
    alert('Date B: ' + B );

    if(B >= A){
        alert('Past Date');
    }

    else{
        alert('Future Date');
    }
},
about 4 years ago · Santiago Gelvez Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda