Date textfield does not support the FormAPI #size & #maxlength attributes.

CommentFileSizeAuthor
#9 date-textfield-size-1105818-9-D7.patch2.68 KBjromine

Comments

jonlhouse’s picture

I agree. I've used the mod for a lot of cool things but I can't seems to figure out how to set the #maxlength property on a 'date_combo' type. Any help would be appreciated

karens’s picture

Status: Active » Closed (works as designed)

#size and #maxlength are attributes for an individual form element. The combo type is a collection of dates which are themselves collections of individual form elements, and the length and size of each of the sub-elements may not be the same. Setting these attributes on a combo date would be meaningless.

vitalie’s picture

Hi, I would like to re-open discussion on this. I am not sure it is meaningless.

I am adding a date field with granularity set only to Year. I need an end date too. The text elements have the default size of 60 - it is two much for a 4-digit input. I would like to be able to set the size of the text fields, even if it was one size for both of them.

Countzero’s picture

Second that : 60 chars for year only is absurd.

Why not rely on the standard form element properties ?

mastoll’s picture

Issue summary: View changes

This is exactly my concern. Has anyone found a way to adjust the element size and maxlength?

Chris Charlton’s picture

No. This issue remains valid.

nicxvan’s picture

I would like to revisit this as well. I have a date field that takes in only the month day and year and the #size attribute is respected. If I have a date field that takes only the hour and time the #size is not respected.

I can see a couple solutions, one pin the #size to what is set, or allow a nested array that defines the size of each element.

Needing to use hook_date_popup_process_alter to get the #size to be what you need seems counter intuitive.

nicxvan’s picture

Status: Closed (works as designed) » Active
jromine’s picture

Status: Active » Needs review
StatusFileSize
new2.68 KB

Patch attached to allow setting size & maxlength for date_text (textfield) input widget.

Chris Charlton’s picture

+1 for #9 (passed tests).

Thanks @jromine!

damienmckenna’s picture

Status: Needs review » Needs work
Issue tags: -fapi size maxlength textfield text date

Thanks for putting that together.

If you don't mind, I'd like to request a few small changes.

  • Please add some help text to remind site builders to make sure that the field has enough space for the values they're expected to fill in.
  • Please change the logic on the admin #default_value fields to use !empty() instead of isset() so that it drops "0" values.
  • Please standardize the labels so that they both clarify they are for the form field.
  • Please amend the "size" field to indicate that this may be overridden via CSS and that different browsers handle it slightly differently, so it is imprecise.

Thanks.