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

200
Visualizações
vanillajs-datepicker get date on click (change)

I'm trying to get a date when I click on a calendar date (change). The doc says there is a event trigger. But can't get it to work. I made a custom Event Listener 'click' however that's triggering the whole calendar.

All Datepicker-event objects are CustomEvent instances and dispatched to the associated element (for inline picker, the block element).

const elem = document.querySelector('#kalenderdatum');
const datepicker = new Datepicker(elem, {
  calendarWeeks: true,
  todayHighlight: true
});

elem.addEventListener('click', function(){
   console.log('test');
   console.log(datepicker.getDate());
 });

https://mymth.github.io/vanillajs-datepicker/#/api?id=datepicker

Can someone please help how to use the customevent trigger.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Here is a working example to add an event, for the Date Range picker( assuming we are using object-oriented programming ( classes ), The changeDate event must be applied to each of the input elements . Note that since I am using Date range Picker there I have two inputs , but in your case you may be using just a single input for Datepicker.

this.dateRangePicker = new DateRangePicker( this.dateRangeEl, { clearBtn: true, } );

      this.dateRangeInputEls = this.querySelectorAll( 'input' );

    if ( this.dateRangeInputEls.length ) {
        this.dateRangeInputEls.forEach( ( dateInputEl ) => {
            dateInputEl.addEventListener( 'changeDate', ( event ) => this.handleDatesSelection( event ) );
        } );
    }
    
        handleDatesSelection( event ) {
    const dateEl = event.target;
    this.selectedDates = this.dateRangePicker.getDates( 'yyyy-mm-dd' );
    const startDate = this.selectedDates?.[ 0 ] ?? '';
    const endDate = this.selectedDates?.[ 1 ] ?? '';

    console.log( 'this.selectedDates', this.selectedDates );
    }
about 4 years ago · Juan Pablo Isaza 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