I've created some text fields using CCK, but the text fields display much wider than they need to be. I was wondering if anyone knows how I can change the #size parameter (see http://api.drupal.org/api/5/file/developer/topics/forms_api_reference.ht... ) to modify the way that a text box appears? I tried modifying the node_field table to add size s:4:"size";s2:"16"; with the following command

update node_field set global_settings = 'a:5:{s:4:"size";s2:"16";s:15:"text_processing";s:1:"0";s:10:"max_length";s:2:"16";
s:14:"allowed_values";s:0:"";s:18:"allowed_values_php";s:0:"";}' where field_name='field_first_name';

(line broken for readability)

But it didn't seem to do anything. Can someone suggest a good way to change how to modify the displayed size of a text box using CCK?

On a related note - I saw "content templates" http://drupal.org/project/contemplate but wasn't sure if that (a) was designed to solve this problem, (b) was still maintained (c) was obsoleted by this http://drupal.org/node/17565 (custom themes per page)

Help?

CommentFileSizeAuthor
#3 cck_text.module_size.patch1.46 KBrar

Comments

rar’s picture

Status: Active » Needs review

Please make the following changes to CCK text.module to specify the size of a text box.

Line 32: add the following

      $form['size'] = array(
        '#type' => 'textfield',
        '#title' => t('Size'),
        '#default_value' => isset($field['size']) ? $field['size'] : '',
        '#required' => FALSE,
        '#description' => t('The displayed size of the field in characters. Leave blank for the default settings.'),
      );

Lines 69:70 (only the second line is modified)

    case 'save':
      return array('text_processing', 'max_length', 'size', 'allowed_values', 'allowed_values_php');

Lines 306:317, (add the line starting with 'size' ...)

        if ($field['widget']['rows'] == 1) {
          $form[$field['field_name']][0]['value'] = array(
            '#type' => 'textfield',
            '#title' => t($field['widget']['label']),
            '#default_value' => isset($items[0]['value']) ? $items[0]['value'] : '',
            '#required' => $field['required'],
            '#description' => t($field['widget']['description']),
            '#maxlength' => $field['max_length'] ? $field['max_length'] : NULL,
            '#size' => $field['size'] ? $field['size'] : '60',
            '#weight' => $field['widget']['weight'],
          );
        }

The changes are small so I wrote them up manually - let me know if you want an actual patch

rar’s picture

Component: CCK in core » text.module
Category: support » bug

updated to show just the text.module and changing to "Bug"

rar’s picture

Title: How to I set #size in CCK text widget? » Patch: Set the size for text fields in CCK
StatusFileSize
new1.46 KB

Patch attached

rar’s picture

Note: the css file /modules/node/node.css will override your "size" field because of the following

.node-form .form-text {                                                       
  display: block;           
  width: 95%;   
}                        

To get the text boxes to show up with the sizes you specify you will have to deal with that.

wisdom’s picture

Status: Closed (duplicate) » Needs review

The patch seems does not help to control the size of text box field with multiple rows. For single row text field adding the following in the style.css file controls the size.
div.node-form input.form-text {
width: 25%;
}
But how to resize multiple rows cck text fields still remains.

karens’s picture

Status: Needs review » Closed (duplicate)

Status: Needs review » Closed (duplicate)