Hate to be a bore but don't you just hate those statements that say something like. "Simply do such-and-such a thing and bob's your uncle, it's done..."

Case in point;
"Richly featured popup calendar library using the Jscalendar library. To use, simply add a 'jscalendar' class to a textfield.

I have installed the Javascript tools module in Drupal 5 and enabled jscalendar.

Nowhere can I see a js calendar class to add to a text field - looked everywhere!

Am I missing something like installing some other module?

Any help would be gratefully appreciated.

Comments

jsloan’s picture

When creating a form using the Drupal forms API you can add the "jscalander" class attribute to the text field via the #attributes declaration.
http://api.drupal.org/api/4.7/file/developer/topics/forms_api_reference....

here is a simple example:

$form['date'] = array(
  '#type' => 'textfield',
  '#title' => t('Date'),
  '#attributes' => array('class' => 'jscalendar'), 
  '#size' => 12, 
);

To set some defaults of the jscalander you add some #jscalendar elements to the form.

  // Use only year, month, and day in textfield.
  $form['#jscalendar_ifFormat'] = '%Y-%m-%d';
  // Don't show time.
  $form['#jscalendar_showsTime'] = 'false';
add1sun’s picture

Adding class to text field you need to get it added in the form code itself like <input type="text" name="example" class="jscalendar" />. AFAIK a number of modules (like Event) have the ability to use jscalendar built in to them at the module level.

What is your use case? Are you creating a custom form somewhere?

Drupalize.Me, The best Drupal training, available all the time, anywhere!

Chris Lozinski’s picture

This is really helpful and suddenly it all makes sense!

What I really wanted was to use jcalendar as a flat calendar which according to http://www.dynarch.com/projects/calendar/ should provide this function. However, it may be that the events module is what I need - jcalendar has more scope for customising the theme - the events calendar is a little garish and is fiddly to customise using CSS.

The pop-up calendar will be very helpful in developing forms now that I have twigged - so thanks very much.

I wonder though whether jcaledar used as a flat calendar will serve as a diary of events or is really just designed for inputting dates etc into a form - anyone know of any examples of how the flat calendar version is used?

lmteijon’s picture

What did you do to make this flat calendar worked?
It isn't a drupal module. Where am I copy the folder that contains the jscalendar1-0?

dhar’s picture

I would like the date to be like this

26/07/2007 - 9:30pm

my format string is


  $form['exam_date'] = array(
....
.....
  ......
    '#jscalendar_ifFormat' => '%Y-%m-%d %h:%i %A',
   
    '#jscalendar_showsTime' => 'true',
  
    '#jscalendar_timeFormat' => '12',
  );

the %h:%i %A is not giving correct results, as they should as indicated by the documentation given at
http://php.net/date.. I'm not sure if I'm making an error somewhere .... any ideas ?

jlalvarezmedina’s picture

Hi everyone! sorry for bothering, but despite I've been googling a lot I couldn't solve my problem. Perhaps is too simple to be considered as such, but here I go.

I've installed all of the required modules for getting JS calendar working. I'm trying to add this functionality to a textfield inside a content type so when I add/edit a node of this type, I can pick the date value from the pop up.

I've read all around the Internet that the way to do so is fairly simple. All what's needed is to add the class jscalendar to the mentioned textfield, using some code like this:

  $form['date'] = array(
    '#type' => 'textfield',
    '#attributes' => array('class' => 'jscalendar'),
  );

but my question (as I'm new to drupal) is: where on earth should I add this code? In a specific file? In some part inside the field properties? I just don't know...

I tried everything I coud before posting, so please don't get upset. Thanks for helping!