is there a way to have the form api just render the year on a date field?

thanks!

Comments

jng12’s picture

ok. How about this.

is there a way to disable (maybe using #disable property) the Month and / or Day in a date field so that the Year select field is the only one enabled?

thanks.

-jayson

mistresskim’s picture

You can control how the date is displayed on the input form using the #date_granularity property. How the date is rendered is determined by the #date_format property, which follows the usual PHP date formatters.

There's some info here about how to define date elements. Also check out date_api_elements.inc in the Date module, which has the lowdown on the FAPI date stuff.

jng12’s picture

Exactly what I was looking for!

thanks Mistress Kim!

:D

jng12’s picture

a little help on date_granularity.

I am a little confused on what it's for. what's the difference between date_granularity and date_format?

thanks in advance.

mistresskim’s picture

My bad. It looks like #date_granularity has been deprecated so I guess just use #date_format.

jng12’s picture

No problem. :D thanks for the help!

Wappie08’s picture

Hello, I'm also trying to manipulate the display of a date field, but this time when it is allready filled in -> I want to make it uneditable when filled in (editing the node)..

$form['field_date'][0]['#attributes']['disabled'] = TRUE;

doesn't work

and there is no #date_format in the array of field_date..

Any help?

Clément’s picture

Hello,

I just had the same problem as you drunk for the date.

It must still go down one level for walking.
Example for the year :

$form['field_date'][0]['value']['year']['#attributes']['disabled'] = TRUE;

To help you you can also view the table :
<?php print '<pre>'; print_r($form['field_date']); print '</pre>'; ?>

Greetings
Clément