Add popup to custom HTML fields

BWPanda - October 26, 2009 - 02:51
Project:Date
Version:6.x-2.4
Component:Date Popup
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Description

I've created my own, custom HTML form with date fields that I'd like to use date_popup. However, I can't seem to get it to work...

The links in the Date_Popup README.txt file tell me to create a function that runs datepicker() on any fields you tell it to, but the following code's not working for me:

$(document).ready(function() {
  $('#depart').datepicker();
  $('#arrive').datepicker();
});

What am I doing wrong?

#1

BetoAveiga - October 27, 2009 - 23:47

I was having the same problem. You first have to load 3 files (at least) using drupal .JS:

(you have to write this inside PHP tags)

drupal_add_js('sites/all/modules/date/date_popup/lib/ui.datepicker.js');
drupal_add_js('sites/all/modules/date/date_popup/lib/jquery.timeentry.pack.js');
drupal_add_js('sites/all/modules/date/date_popup/date_popup.js');

Also at the end of your form you do what you were doing:

$(document).ready(function() {
$('#depart').datepicker();
$('#arrive').datepicker();
});

Probably it's not the best solution, but it works. If you find a better way to do this please post again here.
Hope that works for you, it worked for me :)

#2

BWPanda - October 29, 2009 - 01:21
Status:active» fixed

Thanks BetoAveiga, that works perfectly!

For the record, I used the following code to set a custom format for the date:
$('#depart').datepicker({dateFormat: 'dd/mm/yy'});

#3

System Message - November 12, 2009 - 01:30
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.