Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

199
Views
vanillajs-datepicker obtener fecha al hacer clic (cambiar)

Estoy tratando de obtener una fecha cuando hago clic en una fecha del calendario (cambiar). El documento dice que hay un disparador de eventos. Pero no puedo hacer que funcione. Hice un 'clic' personalizado de Event Listener, sin embargo, eso está activando todo el calendario.

Todos los objetos de evento de selector de fecha son instancias de evento personalizado y se envían al elemento asociado (para el selector en línea, el elemento de bloque).

 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

¿Puede alguien ayudarme a usar el desencadenador de eventos personalizados?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí hay un ejemplo de trabajo para agregar un evento, para el selector de rango de fechas (asumiendo que estamos usando programación orientada a objetos (clases), el evento changeDate debe aplicarse a cada uno de los elementos de entrada. Tenga en cuenta que como estoy usando el selector de rango de fechas allí tengo dos entradas, pero en su caso puede estar usando una sola entrada para 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!