Duplicate counter on paragraph fields

Created on 6 January 2022, almost 3 years ago
Updated 18 July 2023, over 1 year ago

Problem/Motivation

If this widget is applied to a textarea field in a paragraph, the counter gets printed twice (one working, one not) because of L40 in textfield_counter.js

When you inspect the results of the jQuery selection, it returns two items; the `textarea` and the containing `div` because they both have the class being selected applied to them.

Steps to reproduce

Create a textarea in a paragraph with the `textfield_counter` widget turned on.

Proposed resolution

Be more specific about what is being selected. For example:

$("." + fieldSettings.key[index]).not(".description").once("textfield-counter-text-watcher").once("textfield-counter-counter-watcher").each(function () {
 // ...
});

// could be rewritten as

$("." + fieldSettings.key[index]).find("textarea, input[type=text]").once("textfield-counter-text-watcher").once("textfield-counter-counter-watcher").each(function () {
 // ...
});

Since the code in `.each` specifically has ties to an actual input element, it may be wise to specifically target those only, so that any other element that may share that class won't get picked up.

It should also continue to prevent duplicate counters caused by description, since that should never match.

πŸ› Bug report
Status

Closed: duplicate

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jklmnop

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024