Skip Navigation

[Resuelto] Get datepicker value onClose

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem: I would like to access the selected date value in a datepicker field using the onClose event.

Solution: You can access the selected day, month, and year in the second parameter of the callback function. Here's an example:

jQuery(document).ready(function(){
  jQuery('input[name="wpcf-start-date[display-only]"]').datepicker("option", "onClose", function(dateText,inst){
    console.log(inst.selectedDay + ' ' + inst.selectedMonth + ' ' + inst.selectedYear);
  });
});

Keep in mind that in JavaScript month is a zero-based index, so August will be 7.

Relevant Documentation:
http://api.jqueryui.com/datepicker/#option-onClose
https://www.w3schools.com/js/js_date_methods.asp

This support ticket is created hace 6 años, 3 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Este tema contiene 1 respuesta, tiene 2 mensajes.

Última actualización por Christian Cox hace 6 años, 3 meses.

Asistido por: Christian Cox.

Autor
Mensajes
#1093873

Hi,

I'm trying to do the same thing, but I have some problem :

- First if we use :

jQuery('input.hasDatepicker').datepicker('option','onSelect',function(){
    console.log('select');
  });

It appears that all defaults options are removed (default dateFormat ...), so it seems we have to use onClose event to avoid to overwrite defaults toolset datepicker actions previously defined.

- So using onClose, I'm not able to retrieve datepicker value ? Can you help me with that ?

Thank you very much for your help
Best regards

#1093945

You can access the selected day, month, and year in the second parameter of the callback function. Here's an example:

jQuery(document).ready(function(){
  jQuery('input[name="wpcf-start-date[display-only]"]').datepicker("option", "onClose", function(dateText,inst){
    console.log(inst.selectedDay + ' ' + inst.selectedMonth + ' ' + inst.selectedYear);
  });
});

Keep in mind that in JavaScript month is a zero-based index, so August will be 7.
https://www.w3schools.com/js/js_date_methods.asp