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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | charts-3609904-2.patch | 791 bytes | fox mulder |
Issue fork charts-3609904
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 #2
fox mulder commentedPatch attached (tested against 5.2.2).
Comment #3
andileco commentedThank you! Will get to this soon.
Comment #5
nitinkumar_7 commentedTested 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
Comment #6
andileco commentedWould one of you mind creating a MR so that we can get the automated tests/code lints?
Comment #10
andileco commented@fox mulder - @nikathone made your patch a merge request. We've reviewed it and it looks good (plus @nitinkumar_7 reviewed too). Committed.