How do I change body edit box size?

zoon_unit - November 2, 2007 - 14:27

The body text edit box when editing a node is only big enough to display three lines of text and I have to drag the box down every time before editing. How can one change the default size of the edit box to something more "practical?"

same question

zokazola - November 5, 2007 - 16:08

I have asked the same thing and would love to know! Anyone?

Drupal 6 Answer

julester23 - September 9, 2008 - 19:20

So far, the best way I've found is to edit modules/node/node.pages.inc - of course I'm sure this affects all content-types :(.
Look for $form['body'] around line 290 and change the rows below.

The drupal way to do this

WorldFallz - September 9, 2008 - 20:03

The drupal way to do this (if you're using a phptemplate based theme) would be to use the theme_textarea theme function by adding the following to the template.php file for your theme and altering as you wish:

<?php
function phptemplate_textarea($element) {

  if (
$element['#name'] =='body'){  
     
$element['#rows'] = 35;
  }

 
$class = array('form-textarea');
  if (
$element['#resizable'] !== FALSE) {
   
drupal_add_js('misc/textarea.js');
   
$class[] = 'resizable';
  }

 
$cols = $element['#cols'] ? ' cols="'. $element['#cols'] .'"' : '';
 
_form_set_class($element, $class);
  return
theme('form_element', $element, '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>');
}
?>

===
"Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime."
-- Lao Tzu
"God helps those who help themselves." -- Benjamin Franklin
"Search is your best friend." -- Worldfallz

Hi Worldfallz. Thanks for

bwv - January 28, 2009 - 18:33

Hi Worldfallz. Thanks for this pointer. I am trying to apply this to a d6 theme. Here is the relevant code from the API link you provided above. My question is, where would I add the code that limits the number of rows in the default body field to, say 5 rows/ And can I make the field not resizeable? Thanks for your kind assistance.

<?php
function theme_textarea($element) {
 
$class = array('form-textarea');

 
// Add teaser behavior (must come before resizable)
 
if (!empty($element['#teaser'])) {
   
drupal_add_js('misc/teaser.js');
   
// Note: arrays are merged in drupal_get_js().
   
drupal_add_js(array('teaserCheckbox' => array($element['#id'] => $element['#teaser_checkbox'])), 'setting');
   
drupal_add_js(array('teaser' => array($element['#id'] => $element['#teaser'])), 'setting');
   
$class[] = 'teaser';
  }

 
// Add resizable behavior
 
if ($element['#resizable'] !== FALSE) {
   
drupal_add_js('misc/textarea.js');
   
$class[] = 'resizable';
  }

 
_form_set_class($element, $class);
  return
theme('form_element', $element, '<textarea cols="'. $element['#cols'] .'" rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="'. $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>');
}
?>

----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207

_

WorldFallz - January 28, 2009 - 18:41

Hmmm... just a guess, but try this:

<?php
function theme_textarea($element) {
 
$class = array('form-textarea');

 
// Add teaser behavior (must come before resizable)
 
if (!empty($element['#teaser'])) {
   
drupal_add_js('misc/teaser.js');
   
// Note: arrays are merged in drupal_get_js().
   
drupal_add_js(array('teaserCheckbox' => array($element['#id'] => $element['#teaser_checkbox'])), 'setting');
   
drupal_add_js(array('teaser' => array($element['#id'] => $element['#teaser'])), 'setting');
   
$class[] = 'teaser';
  }

  if (
$element['#name'] =='body'){ 
     
$element['#rows'] = 5;
  }
}
?>

Post back if you have any problems.

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

Thank you... unfortunately,

bwv - January 29, 2009 - 09:48

Thank you... unfortunately, it does not appear to work (I changed "theme_textarea" in line one to "name-of-my-theme_textarea"). After inserting the code in template.php, the body field did not change size. Any other suggestions?

I would prefer to create a CCK textarea for this purpose, and would be able to size that as I wanted. But I need to use the maxlength module for the description field to limit to 500 characters the amount of text a user can input. Maxlength does not, from what I can tell, work with CCK textfields, however. So I am, for stylistic purposes, trying to reduce the size of the body field.

Its not critical, just for the sake of appearance. Thanks for your help. regards, david
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207

_

WorldFallz - January 29, 2009 - 14:57

No worries-- that was just a guess. This was tested and worked for me on d6:

<?php
function phptemplate_textarea($element) {
  if (
$element['#name'] =='body'){
     
$element['#rows'] = 3;
     
$element['#resizable'] = false;
  }
  return
theme_textarea($element);
}
?>

Give it a shot and let me know...

===
"Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime." - Lao Tzu
"God helps those who help themselves." - Ben Franklin
"Search is your best friend." - Worldfallz

Wonderful! Thank you, it

bwv - January 29, 2009 - 15:54

Wonderful! Thank you, it works perfectly.

(But not when combined with the maxlength module, for some reason. When maxlength is activated, the body field resorts to its original size and becomes resizeable.)

best, david
----------------------------------------------------------------------
http://classicvinyl.biz
http://music.classicvinyl.biz
http://association.drupal.org/user/1207

thanks

kweq - February 24, 2009 - 21:18

I had similar problem, related with number of cols per textarea.
With help of your post it works for me now!
many thanks, Andrew

Many thanks for this. I'd

sylvie_n - September 8, 2009 - 15:52

Many thanks for this. I'd been puzzling over making modules and analyzing arrays in order to change the width of my description field...this has worked straight away!

subscribing

Yuki - September 8, 2009 - 23:46

subscribing

 
 

Drupal is a registered trademark of Dries Buytaert.