Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update Jquery Datepicker with a variable?

I have a form with Jquery Datepicker and i can save the date in the database.

But when i reload the form to update the datas, i would like to have Jquery Datepicker showing the date previoulsy recorded in the database.

I can load it with php. I just need to update the datepicker.

In the documentation, i see :

beforeShowType: Function( Element input, Object inst ) Default: null A function that takes an input field and current datepicker instance and returns an options object >to update the datepicker with. It is called just before the datepicker is displayed.

I think it can be the solution. Could someone give me an example ?

like image 933
Sébastien Gicquel Avatar asked May 11 '26 05:05

Sébastien Gicquel


1 Answers

What did you attach the datepicker to? If you attached it to an input, then you just need to set the value of the input before calling datepicker() on it.

If you haven't initialized the datepicker yet, you can do:

$( '#yourElement' ).datepicker({ defaultDate: yourDate });

Otherwise, you can call the setDate method to set the date on an already initialized datepicker:

$( '#yourElement' ).datepicker( 'setDate', yourDate );
like image 81
Waxen Avatar answered May 13 '26 18:05

Waxen