Max length storage/widget settings out of sync.

Created on 22 April 2024, 7 months ago
Updated 29 April 2024, 7 months ago

Problem/Motivation

It seem in 3.0x-dev version it is unable to change Maximum length. Once you change the value from the default 255 to any other like 100, it won't allow you to save a page, or add additional field.
I am using here drupal 10.2.5 (it has new layout)

However when I tried with my secondary web where I ma still on drupal 9 and I am currently using version 2.0.2 there is no issue.

So it is related to 3.0.x-dev or drupal 10. (I have tried with multiple admin themes like Claro or Gin with the same result)
After I cancel it (because unable to save) I can see following message on the screen:

Error message

    Max length must be lower than or equal to 100.

Even I tried to create fields with 255 first and after save I want to change the length - the same issue. Unable to click on save button.

๐Ÿ› Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

๐Ÿ‡ธ๐Ÿ‡ฐSlovakia coaston

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @coaston
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mohd sahzad

    Mohd Sahzad โ†’ made their first commit to this issueโ€™s fork.

  • Hi,

    I identified the issue and can provide a manual workaround until a patch can be made.
    Problem is: When creating a new custom field, a new "Text (plain)" item is created by default with a 255 maxlength (Custom field items section of the page) + a new row is added in the bottom table for the item field settings (including maxlength). If you unfold the "Settings" tab of your field item row, you can see the maxlength parameter.
    Now, when you update the maxlength value from the "Custom field items" section (e.g. 150 characters), it does not update the maxlength value in the table row "Settings" tab (although it should) which remains at 255 characters. Hence, when you try to save the form or add a new item, the form does not validate because the values do not match (see attached screenshot for example).

    Manual workaround is to edit both maxlength fields to get rid of the validation error.

  • Status changed to Needs work 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States apmsooner

    Thanks for the report. I am able to reproduce and will work on a solution for this.

  • I had a look at the code for further investigation and ajax works fine. Problem is $element['settings']['maxlength']['#default_value'] (this value is correctly updated) being overriden by $form_state->input value in TextWidget::widgetSettingsForm().

    Maybe adding a condition to reset the input to the default value if it is out of range would fix the issue.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States apmsooner

    I'm thinking I'll just make maxlength in the widget settings required and set the #value property as the same as the #default_value. The reason being is that the widget settings may have value of 255 but the column settings may have changed and have e.g. 100. The maxlength should basically always be set to no more than what the storage allows. I realize i also need to expose the storage max_length for uri and telephone as the type can change from string to uri for example and the max_length storage settings just get inherited without ability to override. I'll have a patch up shortly that can be tested for all this.

  • Merge request !50Fix maxlength. โ†’ (Merged) created by apmsooner
  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States apmsooner
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States apmsooner

    Please try the patch and let me know if this fixes the issue. FYI, the uri and telephone field types now have max_length setting exposed in storage settings to prevent further issues in case the existing field type changes.

  • ๐Ÿ‡ธ๐Ÿ‡ฐSlovakia coaston

    Thank You @apmsooner
    Patch #10 works for me and I am able to change and save the field.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States apmsooner

    Thanks, I will revise this and modify some stuff for uri and telephone fields to get tests to pass. The storage settings on those should actually not be changed so just need to modify some widget settings defaults.

  • Pipeline finished with Skipped
    7 months ago
    #156840
  • Status changed to Fixed 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States apmsooner
  • Status changed to Fixed 7 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States apmsooner
Production build 0.71.5 2024