As far as I can tell, there is no way to enable this form Webform fields. It would be nice to have this functionality. I know Webform is a bit strange in that it doesn't use standard Drupal content types.

Comments

malcomio’s picture

I've managed to get this working on the Drupal 6 version using a form_alter in a custom module.

By doing some debugging with CCK fields inside _maxlength_format_element I found the relevant values for $element['#max_length_properties'].

I used webform_email_this_page as my custom type, effectively to act as a namespace.

The field I was interested in had the field key message, so its ID was submitted-message.

I'm sure it would be possible to use this in D7 with a little adaptation.

If I had time, I'd try to patch the module to add an admin interface on webforms so this could be more generic.

mymodule.install:

function mymodule_install() {
  variable_set('maxlength_message_webform_email_this_page', $max_length);
  variable_set('maxlength_message_js_webform_email_this_page', TRUE);
  variable_set('maxlength_message_text_webform_email_this_page', '!remaining characters remaining');
}

mymodule.module


function mymodule_form_alter(&$form, $form_state, $form_id) {
  if ($form_id == $my_form_id) {
    // add a maximum length with maxlength module
    if (module_exists('maxlength')) {

      $max_length = variable_get('maxlength_message_webform_email_this_page', '255');

      $value = $form['submitted']['message']['#default_value'];
      $field = 'message';
      $id = 'submitted-message';
      $type = 'webform_email_this_page';

      $max_length_properties = array($value, $field, $id, $type);
      $form['submitted']['message']['#max_length_properties'] = $max_length_properties;

      $form['submitted']['message']['#after_build'] = array('_maxlength_format_element');
      $form['submitted']['message']['#maxlength'] = $max_length;
      $form['submitted']['message']['#maxlength_js'] = TRUE;
    }
  }
}
randallknutson’s picture

The latest version of maxlength has been changed to where the sytax is different for webform elements. It is now:

  if ($form_id == $myformid) {
    if (module_exists('maxlength')) {
      $max_length = variable_get('maxlength_message_webform_email_this_page', '255');

      $form['submitted']['message']['#pre_render'] = array('maxlength_pre_render');
      $form['submitted']['message']['#maxlength'] = $max_length;
      $form['submitted']['message']['#maxlength_js'] = TRUE;
    }    
  }

Frederic wbase’s picture

Or you can always use http://drupal.org/project/webform_validation

grts

frederic

thekevinday’s picture

Webform validation is not really a solution here.
Directly supporting the maxlength is desirable if one wants the maxlength on the HTML markup itself.

The second issue is that a custom module may specifically not want to allow users, who can edit a webform, to be able to change/set this maxlength via something like webform validation.

Edit:
Webform validation provides validator hooks, so it only does part of what is needed.
The need for strict HTML maxlength settings on fields is not provided by Webform Validation as far as I can tell.
So there is still a need for this feature request.

While on the topic, are any of the other HTML markup attributes supported?
Standard HTML markup attributes, such as maxlength, need to be properly supported.

cmarcera’s picture

+1 on Maxlength working on Webform Components in D7!

charliecheney’s picture

+1 for Maxlength working on Webform Components in D7 from me as well. Thanks.

haleagar’s picture

Issue summary: View changes
StatusFileSize
new1.25 KB

OK I created a little module that provides an automatic integration bridge between MaxLength and Webform Validation.
It uses the settings from Webform Validation, so there is no administration aspect.
It's really just dependencies defined in .info and a form_alter that gets the settings from Webform Validation and sets the form component settings to trigger maxlength as indicated above by randallknutson.

I don't know if it would be something that would make it's way into MaxLength and Webform Validation since it's dependent on them both, perhaps as a optional sub module?
maxlength_webform.zip

mrrfakier’s picture

Thanks haleagar. Had to tweak your module slightly to get it working using multistep webforms. Other than that it works great.

haleagar’s picture

what was needed? I'll be trying to update this as a patch.

totap’s picture

thx haleagar! #7 is working :)

ak55’s picture

#7 is working like a charm!
Thank you haleagar!

jay-dee-ess’s picture

Status: Active » Reviewed & tested by the community

RTBTC (right?)

jay-dee-ess’s picture

Status: Reviewed & tested by the community » Active

Apologies. Didn't realize this was a separate module.

TwoMice’s picture

#7, Thanks for sharing that module! I've made some improvements, namely adding support for nested webform elements (ie., within fieldsets, etc.). The code is available here: https://github.com/twomice/maxlength_webform

jtjones23’s picture

Thank you TwoMice. Just what I needed this morning.

landsman’s picture

This is can be cool for Drupal 8 too!

aubjr_drupal’s picture

Uploading a copy of the module from #14 just in case that Github repo (or its container account) goes away and nobody around here has a fork.

aubjr_drupal’s picture

StatusFileSize
new2.23 KB

ZIP file attached

laryn’s picture

Thanks, all -- especially @haleager and @TwoMice. And FYI I have included the maxlength_webform functionality directly in the Webform Validation module for Backdrop, and I've submitted a patch for the Drupal 7 version of Webform Validation as well.

cedewey’s picture

Status: Active » Closed (won't fix)

We are putting a feature freeze on the Drupal 7 version of the module, so I'm marking this Closed, won't fix.

ceeez0’s picture

#2 worked for me thanks!