The Linux Page

There are some forms where Drupal '#size' does not seem to work, why?!

I created a form a while back and included an entry like this:

  '#size' => 10

in several text fields of the form. Especially useful when you add a suffix:

  '#field_suffix' => 'Something'

But that would not do anything... I looked at the output of the form and it looked 100% correct. In other words, the input tag had its size="10" properly set. So the next step was to find whether some CSS code would be in the way.

You bet! The node.css file includes the following:

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

The problem is exactly that. Now I know why many forms don't work right in nodes. The reason for that entry is that many themes have a narrow Content area and thus many input fields would not fit the space allowed. It is a good idea to have something like that. The thing is that it is just the wrong CSS. There is a good fix:

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

This does not transform the input tags in blocks (and thus does not prevent the field prefix/suffix capabilities!) and it still applies the 95% but only for those fields that are too large.