Come together with the global Drupal community in Rotterdam, 28 Sept – 1 Oct 2026. Sessions, contribution, connection, and Early Bird savings until 8 June.
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?
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.
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)..
Comments
help!
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
Use the #date_granularity and #date_format properties
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.
PERRRRRRFECT!
Exactly what I was looking for!
thanks Mistress Kim!
:D
confused
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.
#date_granularity is no more
My bad. It looks like #date_granularity has been deprecated so I guess just use #date_format.
thanks!
No problem. :D thanks for the help!
Is this also when editing a node?
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)..
doesn't work
and there is no #date_format in the array of field_date..
Any help?
Hello, I just had the same
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 :
To help you you can also view the table :
<?php print '<pre>'; print_r($form['field_date']); print '</pre>'; ?>Greetings
Clément