Problem/Motivation

Clicking "Add a new default color" on a chart's Display settings does nothing — the AJAX request completes, the form rebuilds, but no new color row is added. The "Remove" button next to existing rows works fine, only "Add" is broken.

Steps to reproduce

1. Create a new simplytest.me project for this project (Charts).
2. Enable a chart library submodule (e.g. "Chart.js Charts") and set it as the default library at /admin/config/content/charts.
3. In the same form's Display settings, find the default colors section.
4. Click "Add a new default color".
5. Observe: no new row appears.

Root cause

In src/Element/BaseSettings.php::processConfigForm(), the "remove" and "add" buttons both derive $element_parents from #array_parents via #array_slicing_args. They sit at different nesting depths — "remove" is 4 segments deep (display/colors/$index/remove), "add" is 5 segments deep (display/colors/_add_new/add_item/submit) — but the "add" button reuses the "remove" button's length => -4 instead of -5. This makes addDefaultColorElementItemSubmit() write the new _new index to the wrong element-state branch, one defaultColorElementItemsAjax() never reads back.

Proposed resolution

Change '#array_slicing_args' => ['offset' => 0, 'length' => -4] to -5 for the "add" button. Patch attached, tested against 5.2.2.

CommentFileSizeAuthor
#2 charts-3609904-2.patch791 bytesfox mulder

Issue fork charts-3609904

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

fox mulder created an issue. See original summary.

fox mulder’s picture

StatusFileSize
new791 bytes

Patch attached (tested against 5.2.2).

andileco’s picture

Status: Active » Needs review

Thank you! Will get to this soon.

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

nitinkumar_7’s picture

Tested patch against 5.2. and confirmed it fixes the bug

steps i followed :
In the default colors section click "Add a new default color."
AJAX request fires and completes same as before.
The form rebuilds and a new default-color is now visibly appended to the list of default colors with the same field structure

andileco’s picture

Would one of you mind creating a MR so that we can get the automated tests/code lints?

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

  • andileco committed 689d39ba on 5.2.x authored by nikathone
    fix: #3609904 "Add a new default color" button on the chart settings...
andileco’s picture

Status: Needs review » Fixed

@fox mulder - @nikathone made your patch a merge request. We've reviewed it and it looks good (plus @nitinkumar_7 reviewed too). Committed.

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

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

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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