Pregunta

Similar to the question posting form on SO, Drupal adds a draggable expander to the bottom of textareas created through the form api. How can I disable this in a nice manner?

¿Fue útil?

Solución

The draggable expander gets added via the behavior defined in 'misc/textearea.js'. From that you can see that it applies to textareas having a class 'resizable'. You can prevent the output of this class if you set the '#resizable' property on a textareas FAPI definition to FALSE (it defaults to TRUE if not explicitly set).

So for your own forms, you can just declare the textareas accordingly. For other forms, youD need to adjust them via hook_form_alter().

Otros consejos

A new module called Disable Resizable Textarea was release now.

This is a simple module that add ability to override the default #resizable property of textarea fields. By default, all textareas are resizable. This module allows you to disable this feature on each field.

It is very easy to set up. Just edit the desired field and you will see an "Disable #resizable property of this textarea" option. You can also disable resizable from its summary, if the field is of type "Long text with summary".

body textarea {
  resize: none;
}

The simplest, would be to remove the file /misc/textarea.js.

The harder, but probably nicer way is to fix this in either your theme, or in a tiny module.

In your theme, you have two options again:

  • use a preprocess to remove the textarea.js from the list of javascript files.
  • use a theme override (yourtheme_textarea) to remove the class resizable-textarea from the rendered HTML. Some information on that in the forums

The option in a module, would be to run a hook_form_alter() to grab any form and run that trough a processor:

/**
 * Implementation of hook_form_alter().
 *
 * Before Drupal 7, there is no way to easily identify form fields that are
 * input format enabled. As a workaround, we assign a form #after_build
 * processing callback that is executed on all forms after they have been
 * completely built, so form elements are in their effective order
 * and position already.
 *
 * @see wysiwyg_process_form()
 */    /**
 * Implementation of hook_form_alter().
 *
 * Before Drupal 7, there is no way to easily identify form fields that are
 * input format enabled. As a workaround, we assign a form #after_build
 * processing callback that is executed on all forms after they have been
 * completely built, so form elements are in their effective order
 * and position already.
 *
 * @see wysiwyg_process_form()
 */
function wysiwyg_form_alter(&$form, &$form_state) {
  $form['#after_build'][] = 'wysiwyg_process_form';
  // Teaser splitter is unconditionally removed and NOT supported.
  if (isset($form['body_field'])) {
    unset($form['body_field']['teaser_js']);
  }
}

function wysiwyg_process_form(&$form) {
  // Iterate over element children; resetting array keys to access last index.
  if ($children = array_values(element_children($form))) {
    foreach ($children as $index => $item) {
      $element = &$form[$item];

      // filter_form() always uses the key 'format'. We need a type-agnostic
      // match to prevent false positives. Also, there must have been at least
      // one element on this level.
      if (($item === 'format' || $item === 'signature_format') && $index > 0) {
        // Make sure we either match a input format selector or input format
        // guidelines (displayed if user has access to one input format only).
        if ((isset($element['#type']) && $element['#type'] == 'fieldset') || isset($element['format']['guidelines'])) {
          // The element before this element is the target form field.
          $field = &$form[$children[$index - 1]];

          $extra_class = '';
          if (!empty($field['#resizable'])) {
            $extra_class = ' wysiwyg-resizable-1';
            drupal_add_js('misc/textarea.js');
          }

          // If we loaded at least one editor, then the 'none' editor will
          // handle resizable textareas instead of core.
          if (isset($loaded) && !empty($field['#resizable'])) {
            $field['#resizable'] = FALSE;
          }
        }
        // If this element is 'format', do not recurse further.
        continue;
      }
      // Recurse into children.
      wysiwyg_process_form($element);
    }
  }
  return $form;
}

These examples are from WYSIWYG module, and slightly altered.

In your theme is far simple, but requires a theme that you can override. The module is both performance-wise worse, and a lot more complex. However, it will work on any theme.

There are to ways how to remove resizable textarea in Drupal (7).

1th Place this simple snipped into your theme template.php. Don't forget to rename THEMENAME to your theme name.

 /**
 * 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;
}

2nd Other way is to use another module called Disable resizable textarea.

More info and source.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top