By jerome@drupal.org on
hello,
I try to set a default value when I create a "article" node, but nothing is display in the body textarea.
In the template.php file in my "homemade" theme, I have registered the function:
function homemade_theme() {
return array(
// The form ID.
'article_node_form' => array(
// Forms always take the form argument.
'arguments' => array('form' => NULL)
)
);
}
And in the function, I try to set a default value for the body field.
function homemade_article_node_form($form) {
$output = '';
$form['body_field']['body']['#title']="test";
$form['body_field']['body']['#default_value']= "test";
$output .= drupal_render($form);
return $output;
}
There is no problem to change the body title but the textarea stays empty.
Please help me to understand my error.
Jerome
Comments
...
From what I recall from my dabbling in FAPI is that textareas can't have default values.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
Do you have any idea how can
Do you have any idea how can I update the body field with a default value?
Jerome
According to the docs you
According to the docs you should be able to do this.
http://api.drupal.org/api/file/developer/topics/forms_api_reference.html...
Although I may have taken this for granted all this time as my default values always seem to be what I've assigned them to be. I just tried this in my own module and sure enough I wasn't able to set the default value to an arbitrary value.
Anyone else have any idea what's going on here?
Okay I muddled with this,
Okay I muddled with this, this morning.
This worked fine for me:
I'm not quite sure what is so different about your code, but hopefully that'll give you a starting point.
...
OK thank you for your assistance.
I will test it now.
Jerome
I've had the same problem. I
I've had the same problem. I eventually figured out that the problem was that my textarea element is in a fieldset (with #tree = true). Moving the form element outside the fieldset showed the default value in the form.
Unfortunately building a simple test to recreate the issue failed to recreate it, so I've not raised a bug, but you may find that moving your textarea out of a fieldset helps.
Try it. It work for
Try it. It work for me.
$form['body'][$form['language']['#value']][0]['#default_value'] = 'The text that you want.';