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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | fix_maxlength_error-3476691-#3.patch | 454 bytes | rubberg |
| #3 | issue-3476691-after-3.png | 86.97 KB | rubberg |
| #3 | issue-3476691-after-2.png | 42.9 KB | rubberg |
| #3 | issue-3476691-after-1.png | 102.7 KB | rubberg |
| #3 | issue-3476691-before.png | 91.39 KB | rubberg |
Issue fork shs-3476691
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
Comment #3
rubberg commentedHi @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.
Comment #4
rubberg commentedComment #5
droces commentedWorks for me; thanks.
Comment #8
joseph.olstadComment #10
joseph.olstadhttps://www.drupal.org/project/shs/releases/2.0.4
https://www.drupal.org/project/shs/releases/3.0.0-beta4