Project:Phone
Version:6.x-2.16
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review

Issue Summary

Perhaps Phone CCK should have a "size of textfield" field (defaulting to 60) as many CCK modules have.

Comments

#1

Version:6.x-2.4» 6.x-2.7

Does anyone know how we can expose the size of textfield field or at least hardcode in a length like 20 in the module?

#2

Subscribing

#3

Use CSS to specify a length. DO NOT hard code a length in the module.

#4

Hi theabacus,

How to do that through css ?

#5

just identify the ID of the input field and add something similar to your css file

#edit-field-home-phone-0-value-1 {
  width: 120px;
}

Why do we not allow #size and #maxlength to alter this field?

#6

subscribing

im with davexoxide... although we can add css to format the field. The field should follow other CCK fields.

#7

subscribing

I agree with the users above - we should be able to specify the field length on forms. It's wider than all of my other fields, when it actually should be one of the smallest. Just looks funny.

Fixing it in local css for now.

#8

Subscribing. I have wasted the best part of a day trying to figure out why this field was so wide (size="60", maxlength="128"). I find it incredible that there isn't a setting for this! Using CSS to adjust the width of a field is ridiculous - this method is affected by the size of font!!!! I'm sorry but this is just bad design of something really very simple and fundamental. Even if you cannot be bothered to expose these settings, you should at least set some sensible defaults! What telephone numbers are 60 or 128 characters long?!!!

#9

Status:active» needs review

Here is a patch that does this.

The core CCK fields already provided this, so this patch makes phone consistent with the core CCK textfield behavior in this regard.

AttachmentSize
phone-6.x-2.x-custom_texfield_size-1.patch 25.58 KB

#10

Version:6.x-2.7» 6.x-2.14

The patch is made against the 2.14 version.

#11

Version:6.x-2.14» 6.x-2.15

Updated the patch to apply against 6.x-2.15.

Also, the default node theme causes problems.
Add one the following blocks of code to your theme's CSS to ensure that the field size gets respected:

/* prevent input fields from being set to a percentage, such as 95% */
div.form-item input.form-text {
  width: inherit;
}

or

/* prevent input fields from being set to a percentage, such as 95% */
div.form-item input.form-text {
  width: auto;
}
AttachmentSize
phone-6.x-2.x-custom_texfield_size-2.patch 1.33 KB

#12

Status:needs review» needs work

@kevinday : The .patch file has been taken into account in 6.2.16 version

Could you describe more how the css code you wrote could be taken into account without having to edit all the styles which are used for the website

#13

It may be possible for phone to include its own custom css file.

If this is to be done, then the first step would be to make sure that appropriate textfields get something specific to phone added.
By using a custom phone-specific CSS class, the changes your module makes via the CSS file will only affect your module.

For the sake of this example, I am calling the phone-specific CSS class: .phone-field-textfield.

Adding the following line will make the .phone-field-textfield CSS class get applied to the phone textfield:

<?php
'#attributes' => array('class' => 'phone-field-textfield'),
?>

such that the you would have:

<?php
$element
[$field_key] = array(
   
'#type' => 'textfield',
   
'#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
   
'#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60,
   
'#autocomplete_path' => FALSE,
   
// The following values were set by the content module and need
    // to be passed down to the nested element.
   
'#title' => $element['#title'],
   
'#description' => $element['#description'],
   
'#required' => $element['#required'],
   
'#field_name' => $element['#field_name'],
   
'#type_name' => $element['#type_name'],
   
'#delta' => $element['#delta'],
   
'#columns' => $element['#columns'],
   
'#attributes' => array('class' => 'phone-field-textfield'),
  );
?>

I think adding a custom css file would be something like:

<?php
/**
* Implementation of hook_init().
*/
function phone_init() {
 
drupal_add_css(drupal_get_path('module', 'phone') .'/theme/phone.css');
}
?>

The contents of that CSS file would be like one of the following:

/* prevent input fields from being set to a percentage, such as 95% */
div.form-item input.phone-field-textfield {
  width: inherit;
}

or

/* prevent input fields from being set to a percentage, such as 95% */
div.form-item input.phone-field-textfield {
  width: auto;
}

#14

Version:6.x-2.15» 6.x-2.16

Can't get the update to work on 2.16.

Could be user error though.

#15

Status:needs work» needs review

Taken into account in 6.2.17 version

Please have a look and tell me if it is OK or still need to be improved

#16

The changes work with one problem.

The #size is specified twice, the second overrides the first:
From phone.module, function phone_textfield_process():

<?php
  $element
[$field_key] = array(
   
'#type' => 'textfield',
   
'#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
   
'#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 60,
   
'#autocomplete_path' => FALSE,
   
// The following values were set by the content module and need
    // to be passed down to the nested element.
   
'#title' => $element['#title'],
   
'#description' => $element['#description'],
   
'#required' => $element['#required'],
   
'#field_name' => $element['#field_name'],
   
'#type_name' => $element['#type_name'],
   
'#delta' => $element['#delta'],
   
'#columns' => $element['#columns'],
   
'#attributes' => array('class' => 'phone-field-textfield'),
   
'#size' => 17,
   
'#maxlength' => 16, // International standard - allow for the plus sign and 15 digits plus separators - this may not be enough for numbers with extensions   
 
);
?>

If you wish to set the size to 17 and still allow users to change it, then why not change the default size to 17 from 60:
From phone.module, function phone_textfield_process():

<?php
  $element
[$field_key] = array(
   
'#type' => 'textfield',
   
'#default_value' => isset($element['#value'][$field_key]) ? $element['#value'][$field_key] : NULL,
   
'#size' => !empty($field['widget']['size']) ? $field['widget']['size'] : 17,
   
'#autocomplete_path' => FALSE,
   
// The following values were set by the content module and need
    // to be passed down to the nested element.
   
'#title' => $element['#title'],
   
'#description' => $element['#description'],
   
'#required' => $element['#required'],
   
'#field_name' => $element['#field_name'],
   
'#type_name' => $element['#type_name'],
   
'#delta' => $element['#delta'],
   
'#columns' => $element['#columns'],
   
'#attributes' => array('class' => 'phone-field-textfield'),
   
'#maxlength' => 16, // International standard - allow for the plus sign and 15 digits plus separators - this may not be enough for numbers with extensions   
 
);
?>

And also change phone.module, function phone_widget_settings() from:

<?php
   
case 'form':
     
$form = array();
     
$size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
?>

to

<?php
   
case 'form':
     
$form = array();
     
$size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 17;
?>

The default value of 60 was introduced by my above patches.
I see no problem with changing 60 to 17.