Hello

I'm trying to change the size of a telephone field on a content type form alter function

Following attempts doesn't seems to work

$form['field_my_telephone']['#size'] = 10;
$form['field_my_telephone']['und']['#size'] = 10;
$form['field_my_telephone']['und'][0]['#size'] = 10;

I've seen this post, but it's related to 8.x and not 7.x (https://www.drupal.org/project/drupal/issues/2527990)

Please any suggestions are welcome

Comments

gusantor created an issue. See original summary.

gisle’s picture

It depends on the theme. For Bartik and most themes, this is the way to control the size of a textfield widget – including phonefield – is:

$form['field_my_telephone']['#size'] = 10;

However, if your theme is Bootstrap or a subtheme thereof, this has no effect. Bootstrap, by default, increases the size of an input to the full width of the container.

When Bootstrap is used as the theme, you must use css to control the size of a textfield. Example:

#edit-my-mobile {
  width: 10em;
}

By the way: This is the case for all Drupal 7 textfield widgets.

The post you link to is about a the Drupal 8 core Telephone module (it does not share any code with this module).

I hope this fixes the issue. Please review.

gusantor’s picture

@gisle Thank you

Using a sub theme of bartik

I'll try css soon

gisle’s picture

Status: Needs review » Fixed

No feedback in three months. Assuming it means it is fixed. You have two weeks to reopen if it is not.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.