Hi

Note: Please forward to the most appropriate project.

Set #size for type textfield to be 3 characters wide, but this attribute is ignored and textfield spans width of browser:

  $form['level_of_effort'] = array(
    '#type' => 'textfield',
    '#title' => t('Level of Effort'),
    '#description' => t('Level of Effort value must be between 0 and 100.'),
    '#size' => 3,
    '#maxlength' => 3,
  );

What does work is #maxlength which does limits the number of characters within textfield.

Ideas what I may be doing wrong?

Thanks

Jeff in Seattle

Comments

litwol’s picture

Project: » Drupal core
Version: » 6.x-dev
Component: Code » forms system
Category: bug » support
Priority: Normal » Minor

Please stop asking drupal core related questions on this project.

Information you may be most interested in is:
Form API reference: http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6
Form API quickstart: http://api.drupal.org/api/file/developer/topics/forms_api.html/6

Good luck.

jennifer.chang’s picture

Version: 6.x-dev » 7.x-dev

confirmed.

jennifer.chang’s picture

Category: support » bug
Priority: Minor » Normal
nevets’s picture

A lot of theme use CSS to set the field length. Try using the Firefox extension firebug to determine the css and change so it uses auto for the width.

Anonymous’s picture

Version: 7.x-dev » 7.0

I'm having a problem like this with one Form API element, I wonder if it is caused by the same thing.

The form element is defined in its own function. That function is called to attach it to the Field configuration form. The same function is also called to attach it to a form defined in my module.

When the textfield is attached to the Field config form, the '#size' attribute is applied. When the textfield is attached to the custom form, the '#size' attribute is ignored.

Anonymous’s picture

My issue had to do with vertical tabs. There is a style in vertical tabs

.vertical-tabs .form-type-textfield input {
width: 100%;
}

This overrides the size attribute on a textfield.

sun’s picture

Status: Active » Closed (duplicate)
Issue tags: -form API, -textfield

Thanks for taking the time to report this issue.

However, marking as duplicate of #970426: Regression: Vertical Tabs styling on input elements overrides specifically set FAPI keys. You can follow up on that issue to track its status instead. If any information from this issue is missing in the other issue, please make sure you provide it over there.

bartes’s picture

Issue summary: View changes

$form['start']=array(
'#type'=>'textfield',
'#title'=>t('test),
'#description'=>t('(Veld verkleinen)'),
'#attributes' => array('maxlength' => 4, 'size' => 4),
'#default_value' => t('1234'),

);

nevets’s picture

Other than posting code, you do not say why you are posting. If it is about 'size', there is css that may change the visual size.