Comments

schnitzel’s picture

Sorry I don't get it. You can define the limit per field in the field-settings of the field? so what else you want to change?

SilviaT’s picture

I think that what mrfelton mean is that you can't set a maxlength for a custom field. I'm using the last dev versionof the module and if I create a custom text field I don't see where I could set the "The maximum length of the field in characters". The countdown is performed only on the "Maximum length" set when the field has been created.

lovegame’s picture

Hello, Well you can do some modify in module to make it work like how you configure node title maxlength.

Open maxlength.module and go to line 126 find code:

element[$child]['#maxlength'] = isset($element[$child]['#maxlength']) ? $element[$child]['#maxlength'] : $ms_elements[$element[$child]['#field_name']]['widget']['settings']['maxlength_js'];

and replace it with this code:

$element[$child]['#maxlength'] = isset($ms_elements[$element[$child]['#field_name']]['widget']['settings']['maxlength_js']) ?  $ms_elements[$element[$child]['#field_name']]['widget']['settings']['maxlength_js']:$element[$child]['#maxlength'];

next go and find the function

function maxlength_form_field_ui_field_edit_form_alter(&$form, &$form_state, $form_id){
# ...
// Add settings for textfield widgets
  $fields = array('text_textfield');
  if (in_array($form['#instance']['widget']['type'], $fields)) {
#...
# Add this Code inside IF
    $form['instance']['widget']['settings']['maxlength_js'] = array(
      '#type' => 'textfield',
      '#title' => 'Maxlength JS',
      '#description' => t('The maximum length of the field in characters.'),
      '#default_value' => isset($form['#instance']['widget']['settings']['maxlength_js']) ? $form['#instance']['widget']['settings']['maxlength_js'] : NULL,
    );
}

i test it and its working fine, i dont know how to make patch, so hope this will help

drupa11y’s picture

StatusFileSize
new16.85 KB

The Code above works for the "maxlength_7.x-3.0-beta1" (patched module attached) but NOT for the latest DEV !!! Can someone update this code?

pakmanlh’s picture

Thanks for effors, the solution of #3 comment works fine for me.
I made a patch including these proposed changes.
Best regards

e0ipso’s picture

Status: Active » Needs review
Raumfisch’s picture

#5 didnt work for me, not for the actual dev and neither for beta-1, so i made a new patch for 7.x-3.0-beta1 from the changes mori posted in #4

Raumfisch’s picture

I had another problem with the patched maxlength module from #7: If there are field_collections in the form containing the same fields like the host entity, the maxlength value of the field_collection is overridden by the setting made from the host entity.

To avoid this i added a few lines of code and made a new patch:

EDIT: Ohps, I just found out that patches should always be posted against the latest development version of the module... I will see if I can make it to update and post it the next days.

wuinfo - bill wu’s picture

StatusFileSize
new2.82 KB

Before I find this thread. I have done a patch for 7.x-3.0-beta1. It did the job in a different way. I thought it is better to keep the check box and allow user to switch on and off the function.

Not allowed to set length larger than the default field maximum length. (This is to avoid possible database error).

User case: Field max length size is set too large at the beginning. Customer require to reduce the length allowed for some fields.

I should upload more later if we found bugs.

wuinfo - bill wu’s picture

StatusFileSize
new3.13 KB

Some warn when you apply the patch: "new blank line at EOF. "

wuinfo - bill wu’s picture

#10 issue tag is a mistake.

pakmanlh’s picture

The issue was opened for version 7.x-3.x-dev, if patch in #5 don't apply on 7.x-3.0-beta1 is not a mistake, feel free to make new versions but realize this.
Thanks

alex.bukach’s picture

Here's patch #8 reworked for latest 7.x-3.x-dev. It works for me.

acrollet’s picture

re-roll

mepushpendra’s picture

Here is the patch for maxlengh version "7.x-3.0-beta1" which worked for me.

mepushpendra’s picture

StatusFileSize
new4.94 KB

Updated patch for for maxlengh version "7.x-3.0-beta1".

robbertnl’s picture

Mistake

robbertnl’s picture

StatusFileSize
new1.69 KB

New patch for for maxlengh version "7.x-3.0-dev".
This is a quick rewrite, it works but might not be the best solution.

joelpittet’s picture

Status: Needs review » Needs work

@robbertnl could you explain the approach compared to #16?

Yours looks quite simple in comparison but there are minor coding standard issues with the else needing a linebreak and a space after the if's starting curly brace.

robbertnl’s picture

StatusFileSize
new3.16 KB

New patch, according coding standards.
The new approach is a simplified version. Not all changes where necessary anymore with the newer commit.
I dont have time to dive into this, but i hoped this changed patch might help others.

joelpittet’s picture

More curious why #16 didn't do the trick for you/what prompted the rewrite?

Coding standard changes on pieces that are not changing make it a bit hard to review so we usually avoid them on hunks of the code that are not being changed. And interdiffs go long to help show the differences from others work if you can provide them. @see https://drupal.org/documentation/git/interdiff

Thanks for the coding standard fixes regardless.

robbertnl’s picture

I wasn't able to apply patch #16. The patch doesn't work anymore with the latest version. Some code of the patch already exist in the newest version of the module

joelpittet’s picture

@robbertnl I see now, sorry that patch looks just that they created it from the wrong location or without --relative in an existing project it seems. The path says a/modules/contrib/maxlength/maxlength.module instead of a/maxlength.module so it may have been created in the sites/all directory.

So it no longer needs to pass around or check the bundle value as it did in 16? I checked to make sure that bit wasn't in 7.x-3.x branch.

kopeboy’s picture

Updates?

This would be really useful when used with the title_field (Title module), because you get automatically replaced title field, which is shared across all content types and with a preset max char of 255 which you cannot change otherwise.

transformative’s picture

I too was trying to use these patches to get Maxlength to work with my Title field (using the Title module).

The patch in #18 got maxlength to work with my Title field (and I assume that #20 would as well).

However, I also noticed another issue, "Override length validation for textfields", with a RBTC patch, which seemed similar to me. I tried it, and it also got maxlength to work with my Title field.

The trouble with both, of them, for me, was that they set a hard limit on the number of characters allowed (similar to how I assume "Force text truncate" is supposed to work). For now, I went back to the module I'd been using before, Soft Length Limit, to achieve what I wanted for the Title field, although I'd rather use Maxlength for everything in the long term.

Mainly, I wanted to point out the similarity between the two issues, as well as the other module, as they could potentially be combined (although one might be broader than the other, or I may not have fully understood their different purposes).

Thanks for the module, and all the work on patches!

philsward’s picture

#20 Works beautifully against 7.x-3.2.

Personally, the styling is a bit over the top for my taste but otherwise it looks good.

daniel korte’s picture

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

#20 wasn't working for me. The maxlength settings were being applied to field collections that it shouldn't be applied to. I re-added the missing bundle code from #16 and everything appears to be working again.

cedewey’s picture

Status: Needs review » 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. Thanks to everyone who worked on this issue. If anyone does want to maintain the Drupal 7 version, do reach out. We'd be happy to bring you on board as a maintainer.