Can't remove tokens from an AI Prompt Type

Created on 5 August 2025, 3 months ago

Problem/Motivation

Trying to remove a token from an AI prompt type is impossible at the moment. Clicking remove, the form reloads, but reloads with 'Variables' section duplicated.

🐛 Bug report
Status

Active

Version

1.2

Component

...to be triaged

Created by

🇺🇸United States kevinquillen

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

Merge Requests

Comments & Activities

  • Issue created by @kevinquillen
  • 🇺🇸United States kevinquillen

    I think this is because of submit buttons not having a unique #name value. If I give Remove a unique value like 'remove_token_$i' then extract that element in the ajax callback, the issue goes away.

  • First commit to issue fork.
  • Pipeline finished with Success
    3 months ago
    Total: 254s
    #565804
  • 🇮🇳India sijumpk

    Kevin, you are right. In a table form element, if we use integer indexes, these buttons do not get grouped properly in the input array. Added the proposed changes and raised the MR. Please review.

  • 🇮🇳India sijumpk

    A warning was also being generated due to the type of the #limit_validation_errors value. As per the documentation, that value should be an array or null. Adding fix for that issue as well.

    Warning: foreach() argument must be of type array|object, true given in Drupal\Core\Form\FormValidator->handleErrorsWithLimitedValidation() (line 151 of /var/www/html/web/core/lib/Drupal/Core/Form/FormValidator.php)

  • Pipeline finished with Success
    3 months ago
    Total: 305s
    #565816
  • 🇺🇸United States kevinquillen

    In that case this change should likely apply to both the variables and token section, not just the token section.

  • 🇬🇧United Kingdom scott_euser

    Thank you for the work on this! Added a nitpick in addition to Kevin's comment in #8 but would be good to add a tiny bit to the test here to ensure removal continues to work in the future https://git.drupalcode.org/project/ai/-/blob/1.2.x/tests/src/Functional/...

    Thank you!

  • Pipeline finished with Failed
    3 months ago
    Total: 262s
    #566853
  • Pipeline finished with Success
    3 months ago
    Total: 204s
    #567157
Production build 0.71.5 2024