Please add support for setting the size of the textfield exactly like the core textfield.

Doing this will make date cck fields more consistent with the CCK core fields.

Comments

Jackl85’s picture

Title: Provide "Size of field" » Size of field (like CCK Text)
Assigned: Unassigned » Jackl85
Status: Active » Reviewed & tested by the community

Do it! :)

NOTE: I USE tag for color text! DO NOT COPY!!!

1. Edit file: date/date/date_admin.inc

In line 19 you FOUND:

    case 'save':
      return array('default_value', 'default_value_code', 'default_value2', 'default_value_code2', 'input_format', 'input_format_custom', 'increment', 'text_parts', 'year_range', 'label_position');

REPLACE WITH:

    case 'save':
      return array('default_value', 'default_value_code', 'default_value2', 'default_value_code2', 'size', 'input_format', 'input_format_custom', 'increment', 'text_parts', 'year_range', 'label_position');

In line 109 you FOUND:

  foreach ($formats as $f) {
    $options[$f] = date_format_date($now, 'custom', $f);
  }

AFTER ADD:

    $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 60;
	$form['input']['size'] = array(
	  '#type' => 'textfield',
	  '#title' => t('Size of textfield'),
	  '#default_value' => $size,
	  '#element_validate' => array('_element_validate_integer_positive'),
	  '#required' => TRUE,
	);

2. Edit file: date/date_api_elements.inc

In line 147 you FOUND:

  $element['#tree'] = TRUE;
  $element['date']['#type'] = 'textfield';
  $element['date']['#weight'] = !empty($element['date']['#weight']) ? $element['date']['#weight'] : $element['#weight'];

AFTER ADD:

    $element['date']['#size'] =  !empty($element['date']['#size']) ? $element['date']['#size'] : $element['#field']['widget']['size'];
Jackl85’s picture

Status: Reviewed & tested by the community » Patch (to be ported)

Maintainers for Date: can you insert in next release?

arlinsandbulte’s picture

Status: Patch (to be ported) » Needs work

It makes things a lot easier and quicker if someone would create a patch file...

thekevinday’s picture

Status: Needs work » Needs review
StatusFileSize
new2.8 KB

Here is the "patch" from #1 put in the requested format.

thekevinday’s picture

Status: Needs review » Needs work
StatusFileSize
new2.89 KB

The patch from #1 (and therefore #4) has most of the work already done, but has missed a few things.

First, the date module provides an option to use the textbox OR a select list.

To be consistent with the core select list, the size of the field cannot be provided for the cases of the select list.
I tried to fix this by wrapping the the input field in the following if condition:
<?php if (in_array($widget['type'], array('date_popup', 'date_popup_repeat'))) { ?>
I guess this part based on a few lines below where <?php if (in_array($widget['type'], array('date_select', 'date_popup', 'date_select_repeat', 'date_popup_repeat'))) { ?> can be found.
If there are any more cases that need to be handled by the mentioned if condition, please correct this patch.

Second, the use of 60 as the default length is perfectly all right. However, date already has hard-coded 20 as the value. To preserve backwards compatibility, I changed the default value from 60 to 20. The changed code looks like:
<?php $size = (isset($widget['size']) && is_numeric($widget['size'])) ? $widget['size'] : 20; ?>

Third, everything about the original patch works, except for when the size gets applied as an attribute.
I have identified the location where the immediate problem occurs to be in the file: date_popup/date_popup.module.
The function to look for is date_popup_process_date.
The affected line is: <?php '#size' => !empty($element['#size']) ? $element['#size'] : 20, ?>
If I manually change the 20 to say 30, I do notice the size of the date field to change.
What this means is that for some reason $element['#size'] is not getting populated.

I do not know why $element['#size'] is not getting populated nor what I need to do to make sure this gets populated (aside from what is already done).
Therefore, I am marking this as needs work.

Attached is the patch from #4 with the fixes for the first and second cases mentioned in this post.

thekevinday’s picture

Status: Needs work » Needs review
StatusFileSize
new4.25 KB

Custom watchdog prints showed the the array key '#size' never was appearing in the $element array for the function date_popup_process_date in the file date_popup/date_popup.module.

However, ['#field']['widget']['size'] did appear in the $element array.

This next patch changes date_popup/date_popup.module such that
<?php '#size' => !empty($element['#size']) ? $element['#size'] : 20, ?>
is now
<?php '#size' => !empty($element['#field']['widget']['size']) ? $element['#field']['widget']['size'] : 20 ?>

With this change in place this feature works as expected.

Please Review

Csabbencs’s picture

Please add support for setting the size and maxlength of the textfield to Drupal 7 version of Date module too!

Chris Charlton’s picture

I just noticed the D7 version of the date_text widget do not support size & maxlength forcing them to default to size = 60 and maxlength = 128.

I filed this issue for D7 - http://drupal.org/node/1105818

brad.bulger’s picture

Component: Date CCK Field » Code
Assigned: Jackl85 » Unassigned
StatusFileSize
new3.25 KB

i've added the textfield widget setting to the patch from #6. it's working well for me. this seems like a sensible feature to add.

linuzboy’s picture

Title: Size of field (like CCK Text) » it needs to be ported to d7
Version: 6.x-2.x-dev » 7.x-2.x-dev
Renee S’s picture

Title: it needs to be ported to d7 » Size of field (like CCK Text)
Renee S’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
damienmckenna’s picture

Issue summary: View changes
Status: Needs review » Closed (won't fix)

Unfortunately the D6 version of this module is no longer supported, but we appreciate the time you put into this.