Home > drupal, drupal 7, field api, field instance > Drupal 7 Field Instances Default Value

Drupal 7 Field Instances Default Value

November 13, 2010 Leave a comment Go to comments

Well, it seems like the drupal documentation is not sufficient in describing how to specify a default value for a programatically created field instance. As of drupal 7 beta-2, if a default value is not specified and say you are performing any ajax operation on the page, the form will throw a validation error.

Here’s how its done.
'al_resource_type' => array(
'field_name' => 'al_resource_type',
'label' => $t('Resource Type'),
'required' => TRUE,
'widget' => array(
'type' => 'options_buttons',
),
// Need to specify a default value, else the form throws a validation
// error while uploading files.
// Used by field_get_default_value
'default_value' => array(array('value' => "1")),
)

One can also use a “default_value_function” to return a default value.

  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.