0

Datepicker is not working. This code working with Drupal 6, but not with Drupal 7.

drupal_add_js(drupal_get_path('module', 'PROPERTY') .'/jquery/jquery-1.4.1.js', 'module');
drupal_add_js(drupal_get_path('module', 'PROPERTY') .'/jquery/jquery.min.js', 'module');
drupal_add_js(drupal_get_path('module', 'PROPERTY') .'/jquery/jquery-ui.min.js', 'module');
drupal_add_js(drupal_get_path('module', 'PROPERTY') .'/jquery/datepicker.js', 'module');
drupal_add_js(drupal_get_path('module', 'PROPERTY') .'/jquery/ztfb_datepicker.js', 'module');
drupal_add_css(drupal_get_path('module', 'PROPERTY') .'/jquery/ui.all.css', 'module');

drupal_add_js(drupal_get_path('module', 'PROPERTY') .'/jquery/scrollJump.js', 'module');
$(document).ready(function() {       
  $("#startdate").datepicker({
    dateFormat:'dd-mm-yy',
    autosize:false,
    changeYear:true,
    changeMonth:true       
  });
});  

I include the file in PROPERTY_Form.admin.inc file.

require_once("D://wamp/www/propertysite/cron/includes/jquerydatepicker.php");

function PROPERTY_Form() {
  global $user; 
  $form = array();

  $form['PROPERTY_Form']['startSyncFrom'] = array(      
    '#type' => 'textfield',
    '#prefix'=>'<tr><td>',
    '#suffix'=>'</td></tr>',
    '#id'=>'startdate',
    '#default_value'=>date('d-m-Y'),
    '#description' => '(You can select any past date to ensure even your old Data gets synced)',
    '#attributes'=>array('tabindex'=>9,'style'=>'width:70px;'),
  ); 

  return $form;
}
0

1 Answer 1

1

You do not have to include all of that jquery libraries: Drupal core has that libraries. You can just include any jquery.ui library with drupal_add_library('system', 'ui.datepicker') or another library which you want to include. Then, in your JavaScript file, you can write something like this.

(function ($) {
  Drupal.behaviors.custom_js = {
    attach: function(context) {
      $('#YOURID input[type="text"]').datepicker({
        showOn: "button",
        buttonImage: Drupal.settings.basePath + "sites/all/themes/YOURTHEME/images/calendar.png",
        dateFormat: "dd-mm-yy",
        showAnim: "slideDown",
        buttonImageOnly: true
      });
    }
  };
})(jQuery);

If you want to use the datepicker with the form API, you have to change the type element to 'date_popup'.

2
  • drupal_add_library('system','ui.datepicker'); drupal_add_js('jQuery(document).ready(function(){jQuery( "#startdate" ).datepicker({ dateFormat: "dd/mm/yy", autoSize: true });});', 'inline'); while puting in PROPERTY_Form.admin.inc file its works Apr 2, 2013 at 9:02
  • This is working fine for me thanks. With out Drupal behaviors, I have added it in my custom js. Icon disabled when there is error in form. With behaviors its working cool.
    – Kalidasan
    May 30, 2014 at 11:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.