Increase the #maxlength of the Selector and container elements

Created on 21 September 2023, about 1 year ago

Problem/Motivation

By default, Drupal has a a #maxlength value of 128 for text fields, however certain sites require more specific selectors to match against.

Steps to reproduce

Attempt to add a CSS selector longer than 128 characters to the Toc.js block. e.g. for the Container and Selectors element.

Proposed resolution

Increase the limit to something larger like 2048, the default browser value is 524,288.

Remaining tasks

Provide issue fork/patch.

User interface changes

UI now allows users to put in longer text values.

📌 Task
Status

Active

Version

2.0

Component

Code

Created by

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

Merge Requests

Comments & Activities

  • Issue created by @codebymikey
  • Status changed to Needs review about 1 year ago
  • @codebymikey opened merge request.
  • 🇮🇳India shiv_yadav

    Hi codebymikey,
    increase the length of two input field.
    added patch.

  • Status changed to Needs work about 1 year ago
  • 🇫🇮Finland heikkiy Oulu

    I cannot make the above patch work.

    Tested by applying the patch and I can see the maxlength changes in the PHP code to:

    $form['selectors'] = [
          '#type' => 'textfield',
          '#title' => $this->t('Selectors'),
          '#description' => $this->t('Elements to use as headings. Each element separated by comma.'),
          '#default_value' => $this->configuration['selectors'],
          '#maxlength' => 2048,
        ];
    

    But when I open the ToC.js settings in the admin, it still limits the maxlength to 128. Tested with Firefox and Chrome browser and tried clearing both Drupal and browser caches multiple times.

    The input HTML is still:

    <input data-drupal-selector="edit-selectors" aria-describedby="edit-selectors--description" type="text" id="edit-selectors" name="selectors" value=".text-long h2:not(.accordion__content h2), .text-long h3:not(.accordion__content h3), .field-section-title h2:not(.accordion__content h2), .content-bottom h2:not(.accordion__content h2)" size="60" maxlength="128" class="form-text form-element form-element--type-text form-element--api-textfield" data-drupal-states="{&quot;visible&quot;:{&quot;:input[name=\u0022toc_js_active\u0022]&quot;:{&quot;checked&quot;:true}}}">
    
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India shiv_yadav

    Hello HeikkiY, I verify on chrome & firebox. It's working fine maxlength show 2048. Attached screenshot as well.
    Thanks.

  • 🇫🇮Finland heikkiy Oulu

    Very weird. I tried to apply the patch to our main branch and the patch applies fine but the maxlength doesn't change. I first suspected it might be because of Gin theme but I get the same result with Claro.

    What admin theme are you using when the maxlength value changes?

    The patch definitely applies fine against 2.1.0 but I don't see the relevant change in the actual produced HTML element.

  • 🇮🇳India shiv_yadav

    Hello HeikkiY ,
    - I verify same both browser.
    - drupal 10.1.5 & drupal -9.5.11
    - admin theme- Claro
    - theme - Olivero

  • 🇫🇷France flocondetoile Lyon

    patch #5 is wrong. It handle only the TocJs Block. You should use patch #4

  • Status changed to RTBC about 1 year ago
  • 🇫🇮Finland heikkiy Oulu

    Thanks @flocondetoile.

    Tested patch from #4 and it applies fine and fixes my issue. I did think about if there was another solution to remove the 255 limit except giving a new arbitrary number like removing the maxlength limititation completely but maybe this is good enough.

    Marking this as RTBC now.

  • 🇫🇷France mably

    @flocondetoile should we add this fix to the 3.0.x-dev branch?

  • 🇫🇷France flocondetoile Lyon

    But need to be updated with the new TocJsPerNodeBlock too, added in 3.x

  • Assigned to mably
    • mably committed 1cb7eb59 on 3.0.x
      Issue #3388836 by codebymikey, shiv_yadav, mably: Increase the #...
  • Status changed to Fixed 4 months ago
  • 🇫🇷France mably

    Merged.

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

  • Issue was unassigned.
Production build 0.71.5 2024