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.

Advertisements
  1. June 16, 2013 at 2:03 pm

    It’s going to be finish of mine day, but before ending I am reading this enormous piece of writing to increase my knowledge.

  2. April 10, 2014 at 8:26 am

    whoah this weblog is excellent i really like studying your articles.
    Stay up the good work! You recognize, a lot of persons are searching
    around for this information, you can aid them greatly.

  3. May 14, 2014 at 6:16 am

    Folks inside the Currency exchange community read online trading reviews , trading articles, watch trading videos, and so
    are always seeking to get the maximum amount of information
    and resources as they possibly can. Franklin was very courteous and
    attempted to be very helpful. However, they disappeared out there because of their diminished demand; however they’re again getting popular with a
    big swing and are avalable in lots of latest modern styles.

  4. June 19, 2014 at 12:07 pm

    Excellent beat ! I would like to apprentice while you amend your web site, how could i subscribe for a blog website?
    The account aided me a appropriate deal. I have been tiny
    bit familiar of this your broadcast offered vivid clear idea

  5. June 22, 2014 at 2:49 pm

    I have been surfing on-line more than three hours today, yet I
    by no means found any attention-grabbing article
    like yours. It is lovely worth sufficient for me. In my opinion, if all website owners and bloggers made excellent content as you did, the internet will
    be a lot more useful than ever before.

  6. June 27, 2014 at 6:47 pm

    I visited many sites but the audio feature for audio songs current at this site is in fact excellent.

  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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: