August 2013

How to use the jquery datepicker in drupal 7

tution_module.js

jQuery(document).ready(function(){
   $(".tut_datepicker").datepicker({
   dateFormat: "mm-dd-yyyy",
   });
});

tution.module
$form['start_date'] = array(
   '#type' => 'textfield',
   '#title' => t('Tution Start Date'),
   '#default_value' => '',
   '#size' => 11,
   '#attributes' => array('class' => array('tut_datepicker'))
);

$form['#attached']['js'] = array(
   drupal_get_path('module', 'tution') . '/tution_module.js' => array(
     'type' => 'file',
   ),
);

Converting the attributes from drupal 6 to drupal 7

Drupal 6:

$form['start_date'] = array(
'#type' => 'textfield',
'#title' => t('Tution Start Date'),
'#default_value' => '',
'#size' => 11,
'#attributes' => array('class' => 'tut_datepicker')
);

drupal 7:

$form['start_date'] = array(
'#type' => 'textfield',
'#title' => t('Tution Start Date'),
'#default_value' => '',
'#size' => 11,
'#attributes' => array('class' => array('tut_datepicker'))
);

How to create item list in drupal 7

$listItem = array('Drupal6','Drupal7');

theme_item_list(array('items'=>$listItem,'title'=>'', 'type'=>'ul', 'attributes'=>array('class' => 'dlist')))