Does anyone know do set the input field size for cck module. As by default the text input field size was set to 60, which it rather too long.

Comments

nisguy’s picture

it would be nice to specify the length when setting up the field.

lenkkivihko’s picture

I had the same issue.

Solution is here:
http://drupal.org/node/113399#comment-193937

Look for your HTML source for proper CSS tag code.

Harjoituspäiväkirja - www.lenkkivihko.fi

dtrdewaele’s picture

I've did a CCK hack for this. CCK I'm using is 5.x-1.7

cck/text.module

Line 40

$form['size'] = array(
  '#type' => 'textfield',
  '#title' => t('Size'),
  '#required' => FALSE,
  '#default_value' => isset($field['size']) ? $field['size'] : '',
  '#description' => t('This will set the size of the input field'),
);

Line 74
Added size to this array

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

Line 383

if (isset($field['size'])) {
  $form[$field['field_name']][0]['value']["#size"] = $field['size'];
}

Now you can set the for every textfield in CCK.

Greetz

Dieter

manic78’s picture

Unfortunately CCK doesn't allow cofigure such attributes like this (yet). I hope this option will be added in the future.

I found a solution using hook_form_alter(). The CSS solution (set width: property) did not worked for me for file attachment fields :(

So there it is:

function yourmodule_form_alter($form_id, &$form) {
  if ($form_id == 'id_of_your_form') {
    $form['your_cck_field_group_name']['your_cck_field_name']['#size'] = 40;
  }
}

You can print the whole $form array by adding this to your hook_form_alter() function:

print_r($form);

and if you don't know the form_id of the desired form put this line in for testing:

print($form_id);

Now you can easily find your form_id and the cck field attributes in $form array, then just set the #size property whatever your theme needs.

(Note: the array path may not match this one I included above.)

Cheers: manic

redraven’s picture

:)

senpai’s picture

Thanks for the code example, guys, and what a simple solution for changing the width of all form fields. Nice!
http://drupal.org/node/186019
[/Senpai]

****
Joel "Senpai" Farris | certified to rock score

yeeloon’s picture

Hi manic78,

Can you please tell me how do I actually implement the above code.

I would like to alter my registration form. An example of view source extracted:

 <input type="text" maxlength="60" name="uprofile_node_form[field_uprofile_fname][0][value]" id="edit-field-uprofile-fname-0-value"  size="60" value="" class="form-text required" />

How do I substitute the right code into and into which particular file? Kindly please advice.

Thanks!

yeeloon’s picture

how can i accomplish the above coding? The instruction is not clear for new starters like myself.
:-(

tantotea’s picture

I try that $form['field_...']['#size'] = ..., inside my .._form_alter function, but it doesn't change the size of my text field - it remains 60.

I am sure that my form_id is correct, the name of the field is correct, no group in my case, and my .._form_alter function is ok because inside it I can alter another cck field.

What could be the cause? Thanks in advance.

tantotea’s picture

Just read that it is a known issue of CCK
http://drupal.org/node/145701
After applying the patch described there, now I can set the field size

suityou01’s picture

I may have missed the point here, but this is how I declare a text field of size 10 characters.

$form['post_code'] = array(
		'#title' => t('Post Code'),
		'#type' => 'textfield',
		'#size' => 10
	);

This works for me, in drupal 5.7

yeeloon’s picture

Hi suityou01,

Can you guide on how to actually change the input field length of a CCK?

Where do I need to insert the above code into?

Thanks in advance!

- yeeloon