Problem/Motivation

When trying to save a node with many tags (using SHS), I get an error saying:

"{field name} cannot be longer than 128 characters but is currently {number} characters long."

When I inspect the HTML, I see that it saves the target IDs in a "textfield" form field, that has a maxlength="128" attribute. This is unnecessarily short and preventing me from saving the node.

When I review the module code, I see that in:
/shs/src/Plugin/Field/FieldWidget/OptionsShsWidget.php, in formElement(), line 164 is:
$element['#type'] = 'textfield';
which changes the field type to textfield. However that also uses the default maxlength of 128.

If I add the following line right after it:
$element['#maxlength'] = 500;
Then I'm able to save the node with way more tags.

But 500 is an arbitrary maximum length, so I'm not sure how to determine the ideal length.

Issue fork shs-3476691

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

droces created an issue. See original summary.

rubberg made their first commit to this issue’s fork.

rubberg’s picture

Hi @droces,

I reproduced the error you described above (see caption with suffix "before").

I made a patch to remove maxlength limitation on the text field once it is built and not during its construction (after Drupal applied the 128 chars limitation), and was able to exceed the field length limitation and saved a 134 chars string with no errors (46 taxonomy terms saved : see 3 captions with suffix "after").

Tested on Drupal 10.3.10 with SHS module version 2.0.0.

rubberg’s picture

Status: Needs work » Needs review
droces’s picture

Status: Needs review » Reviewed & tested by the community

Works for me; thanks.

  • joseph.olstad committed f5826fa3 on 2.0.x
    [#3476691] fix: Max length of 128 preventing saving lots of referenced...

  • joseph.olstad committed 7509bea4 on 3.0.x
    [#3476691] fix: Max length of 128 preventing saving lots of referenced...
joseph.olstad’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.