I'm using the webform module and loving it, but I dont like the resizable textarea to be enabled on the frontend of my website.

There doesn't seem to be an option to enable/disable it globally or in the webform module so I tried implementing this:

function mymodule_form_alter($form_id, &$form) {
  foreach (element_children($form) as $key) {
    if ($form[$key]['#type'] == 'textarea') {
      $form[$key]['#resizable'] = false;
    }
    mymodule_form_alter($form_id, $form[$key]);
  }
}

this code is made to stop WYSIWYG textareas to be resizable. I simply went through the webform files looking for the
[php]
'#type' => "textarea",
[/php]
code and putting:
'#resizable' = false;
right below it, but it did not seem to have effect.

Does anyone know a fix for me?

Thanks in advance,
JR

Comments

taslett’s picture

Hi peach,
You could try overriding the theme_textarea function.
in your template.php file add:

function phptemplate_textarea($element) {
  $class = array('form-textarea');
 
  $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>');
} 

It just leaves out the code below which makes the element resizeable.

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

---------------------
www.csscreator.com

Dublin Drupaller’s picture

hiya,

The textarea labels displayed as just "array" when I used your snippet. Assume it's for 4.6 or an earlier version.

this snippet worked for 4.7:

(A) put this into a template.php file (use a text editor to create one if there isn't one already in your theme folder)

(B) Upload it to your theme folder to override the reasizable text area thingy

function phptemplate_textarea($element) { 
  $class = array('form-textarea'); 
  $cols = $element['#cols'] ? ' cols="'. $element['#cols'] .'"' : ''; 
  _form_set_class($element, $class); 
  return theme('form_element', $element['#title'], '<textarea'. $cols .' rows="'. $element['#rows'] .'" name="'. $element['#name'] .'" id="' . $element['#id'] .'" '. drupal_attributes($element['#attributes']) .'>'. check_plain($element['#value']) .'</textarea>', $element['#description'], $element['#id'], $element['#required'], form_get_error($element)); 
} 

hope that helps someone else. By using this snippet, you are just disabling the default textarea resizer for that specific theme.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate

jurriaanroelofs’s picture

thanks mate, I just settled with the resizeable area on my last site but I'll bookmark this thread for my next sites :D

-------------------------------
http://www.sooperthemes.com/#-Drupal-Themes

clashfan’s picture

I tried that snippet in 4.7.2 but keep getting the following errors when I switch back to a different theme.

Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/goldenboyband.com/httpdocs/content/themes/goldenboy/template.php:10) in /home/httpd/vhosts/goldenboyband.com/httpdocs/content/includes/common.inc on line 266.

Also when I tried to add a menu. I get a blank page.

FredCK’s picture

Hi Dub,

You did a nice job... but maybe the following implementation is better. It is simpler and will also handle future changes in the theme_textarea core function:

function phptemplate_textarea($element) 
{
	$element['#resizable'] = false ;
	return theme_textarea($element) ;
} 

FredCK

norio’s picture

Thanks Fred! I'm using this on www.JogMyMemory.co.za now. Saves me a lot of CSS hassles!

garet’s picture

The above solution works great in D6. Thanks for the post.

function phptemplate_textarea($element)
{
$element['#resizable'] = false ;
return theme_textarea($element) ;
}

spiffyd’s picture

Used this in my templates.php

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

The resizing grip is still visible on my textareas and I still see class "resizeable" in HTML. I am using marinelli theme... I also tried

<?php
function phptemplate_textarea($element)
{
$element['#resizable'] = false ;
return marinelli_textarea($element) ;
} ?>

Didn't work.

daddydo’s picture

Hi,

function phptemplate_textarea($element) 
{
$element['#resizable'] = false ;
return theme_textarea($element) ;
} 

The above shown code of FredCK is working in D6 but unfortunately it takes all drupal core textareas away. Totally vanished. It should only point to the webform module. Couldn't find the right code.

sunset_bill’s picture

the above snippet worked fine in D5 when I tried it just now

I was even able to add

$element['#overflow'] = 'visible';

and get a scrollbar so responses aren't limited to the size of the textarea when resizing is off.

I'm not doing any textareas in the webforms I'm using, but the above code is working for me in both my contact form (which is pretty much the only core textarea I'm using), and in my CCK forms.

salud,
Bill

borgo’s picture

By this function in template.php I turned off resizing for non admin users. At least in D6.

function phptemplate_textarea($element){  			
	if (!user_access('administer nodes')) {
		$element['#resizable'] = false ;		
	}
	$output = theme_textarea($element);
	return $output;
}
jacobmn’s picture

This suggestion breaks those text areas for me. They just disappear.

alduya’s picture

I changed this a little bit to only affect the textareas on node creation pages.

/**
 * Removes the resizable functionality from the textareas if they are not on a node creation page.
 * The node body textarea disapears when it is not resizable.
 */
function phptemplate_textarea($element) {
  if (strpos($_GET['q'], 'node/add') !== 0) {
    $element['#resizable'] = FALSE;
  }
  return theme_textarea($element);
}
jusaf’s picture

If someone wants to remove the resizable part of a specific textarea, you can also JQuery for that (D6):

in your .js file:

Drupal.behaviors.your_module = function(context) {
 
	$("#ID-of-the-textarea").removeClass('resizable');
}

or directly in PHP:

  drupal_add_js('$(document).ready(function(){ $("#ID-of-the-textarea").removeClass("resizable");});', 'inline');

works for me, hope that will help someone..

jaochoo’s picture

In Drupal 6, use the following hook_form_alter() code to disable the resizable textarea for a specific textarea:
  1. You need to create your own module to use hook_form_alter() (it is easy to do that, just check the Drupal documentation, you just need to create a yourmodulename.info and yourmodulename.module file)
  2. Install the Devel model, enable it in the Drupal admin backend, and use te dsm() function in the code snippet below to find out the ID of the form you want to change
  3. Add the code snippet below to yourmodulename.module file

/**
* Implementation of hook_form_alter().
*/
function yourmodulename_form_alter(&$form, $form_state, $form_id) {
  // use the following two calls to find out the ID of the form you want to change; disable/uncomment it again afterwards
  //dsm($form_id);
  //dsm($form);
  switch ($form_id) {
    case 'the_id_of_the_form_you_want_to_change':
      $form['the_name_attribute_of_the_textarea_you_want_to_change']['#resizable'] = FALSE;
    break;
  }
} // function yourmodulename_form_alter

nhepner1’s picture

To remove resizing from a CCK textarea in drupal 6 is a little crazier. Start with the hook_form_alter() like above. You'll also need a hook_nodeapi()

The problem is that CCK doesn't use a 'textarea' type field for textareas, but a 'text_textarea' type that does not support the "'#resizable' => FALSE" parameter.

To get around this, remove the target cck field from the form and replace with a textarea form element:

function function mymodule_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'target_node_form':
      unset($form['field_target_form_element']);

      $form['target_form_element_replacement'] = array(
        '#type' => 'textarea',
        '#title' => t('Target Title'),
        '#resizable' => FALSE,
      );
}

Then initiate our hook_nodeapi to make sure your new field is saved correctly in the node to the field that you want.

The form values are saved in the $node, so we have direct access to them in this function. Use the 'presave' op to change the values before it saves:


function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
  switch($op) {
    case 'presave':
      $node->field_target_form_element[0] = array(
        'value' => $node->target_form_element_replacement,
        '_error_element' => 'target_form_element_replacement' //Set this to target the replacement form element if something goes wrong.
      );
			
      unset($node->target_form_element_replacement); // Don't forget to unset the redundant value.
      break;      
}

It's a lot of work for something so small, but it'll get the job done.

rahulbot’s picture

I didn't have to do that field type swap. I just did this and it worked for me.


// hook into form_alter to add an afterbuild callback
function MYMODULE_form_MYCCKTYPENAME_node_form_alter(&$form, $form_state) {
	$form['#after_build'][] = 'MYMODULE_form_MYCCKTYPENAME_node_after_build';
}

// in the afterbuild callback for my form, change my text field to not be resizable
function MYMODULE_form_MYCCKTYPENAME_node_after_build($form, &$form_state) {
	// make the textarea non-resizeable
	$form['MYTEXTAREAFIELDNAME'][0]['value']['#resizable'] = false;
	return $form;
}

homoludens’s picture

For reference: this is very nice solution (overriding theme_textarea in template.php): http://drupal.org/node/296908

datarazor’s picture

To fully disable the resizing, you also need to add some CSS to your theme:

textarea{
resize: none;
}

otherwise you will still get a bottom corner handle.

Olof Resare’s picture

HOOK FORM ALTER
...['#resizable'] = FALSE;

+

CSS
textarea{
resize: none;
}

Excactly what i needed for D6 =)
Tnx datarazor

jananiporkodi’s picture

This saved my day. Very simple solution and worked fine. Thanks datarazor!

emcniece’s picture

Was trying to disable this on the comment form textarea, but had no luck with this code in a custom module:

	unset($form['comment']);
	$form['comment'] = array(
		'#type' => 'textarea', 
		'#title' => t('Body'), 
		'#default_value' => '', 
		'#required' => TRUE,
		'#resizable' => false
	);

Instead, ended up adding some basic css:

#edit-comment-wrapper .grippie {
	display:none;
}

... just in case anyone else has that issue.

drupalreggie’s picture

perfect solution using CSS injector Thanks!

ferjan’s picture

How can I remove the resizable text box of my contact form in drupal 7?

http://www.digisized.info

metaflexion’s picture

I needed to fix the vertical height of the textarea for comments to a particular content type, but not limit the amount of text they could enter. ie allow scrolling.

<.node-chat-with-a-character> is the node class for a particular content type I had created.

I did it with a couple of lines of CSS I also had to remove visibility of the "grippie" div
Since I was in there theming comments

.node-chat-with-a-character  .comment-form textarea
{resize:none;overflow:scroll;}
.node-chat-with-a-character  .comment-form .grippie 
{display: none;}

Another handy snippet of CSS will put the comment submission form above the submitted comments

/*put comment submit above comments*/
.node-chat-with-a-character #comments 
{ position: relative;  padding-top: 400px;}

.node-chat-with-a-character #comments .comment-form
{position: absolute; height: 400px; top: 0px;}
adamb’s picture

For anyone else still having this problem, here is the fix that worked for me!

/**
* Ensure Text areas are never ever resizeable EVER!
*/
function THEMENAME_textarea($element) {
$element['element']['#resizable'] = FALSE;
return theme_textarea($element) ;
}

tregismoreira’s picture

Now we have a simple module to Disable Resizable Textarea :)

jasom’s picture

Why to install new module (and slow down your installation) when you can fix resizable textarea with simple template.php snippet. Place this code into your template.php and that's it:

/**
 * Override of theme('textarea').
 * Deprecate misc/textarea.js in favor of using the 'resize' CSS3 property.
 */
 
function THEMENAME_textarea($variables) {
  $element = $variables ['element'];
  element_set_attributes($element, array('id', 'name', 'cols', 'rows'));
  _form_set_class($element, array('form-textarea'));

  $wrapper_attributes = array(
    'class' => array('form-textarea-wrapper'),
  );

  $output = '<div' . drupal_attributes($wrapper_attributes) . '>';
  $output .= '<textarea' . drupal_attributes($element ['#attributes']) . '>' . check_plain($element ['#value']) . '</textarea>';
  $output .= '</div>';
  return $output;
}
henryhu’s picture

The module works for me. Thanks @tregismoreira

jaypan’s picture

You can also do this in your CSS:

.grippie {display:none;}
textarea {resize:none;}

Contact me to contract me for D7 -> D10/11 migrations.