Skip to content

fix(key-value): revalidate key control when forbidden keys change after deletion#35455

Merged
adrianjm-dotCMS merged 1 commit intomainfrom
32114-key-value-validation-refresh
Apr 24, 2026
Merged

fix(key-value): revalidate key control when forbidden keys change after deletion#35455
adrianjm-dotCMS merged 1 commit intomainfrom
32114-key-value-validation-refresh

Conversation

@adrianjm-dotCMS
Copy link
Copy Markdown
Member

@adrianjm-dotCMS adrianjm-dotCMS commented Apr 24, 2026

Problem

When a user typed a duplicate key in the Key/Value field, the duplicatedKey validation error appeared correctly. But if the original conflicting entry was deleted, the error remained on the input — preventing the user from saving — even though the conflict no longer existed.

VIDEO

Screen.Recording.2026-04-24.at.2.53.47.PM.mov

Root Cause

The keyValidator() in DotKeyValueTableHeaderRowComponent reads the $forbiddenkeys signal at validation time. Angular reactive forms, however, only re-run validators when the control's value changes — not when an external signal changes. So when $forbiddenkeys updated after a deletion, the key control had no reason to revalidate.

Fix

Added a constructor effect() that watches $forbiddenkeys and calls keyControl.updateValueAndValidity({ emitEvent: false }) whenever the forbidden keys map changes. This forces Angular to re-run the validator with the updated map.

constructor() {
    effect(() => {
        this.$forbiddenkeys();
        this.keyControl.updateValueAndValidity({ emitEvent: false });
    });
}

Test

Added a regression test that:

  1. Sets key control value to a forbidden key → error appears
  2. Updates forbiddenkeys input to empty map (simulating deletion of the conflicting entry)
  3. Flushes effects and asserts the error is cleared

Closes

Closes #32114

This PR fixes: #32114

…er deletion

When a conflicting key/value entry was deleted, the duplicate key error
remained on the input because Angular only re-runs validators on value
change. An effect now watches the $forbiddenkeys signal and calls
updateValueAndValidity() to keep validation in sync with the list.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Apr 24, 2026

Claude finished @adrianjm-dotCMS's task in 37s —— View job


Rollback Safety Analysis

  • Read rollback-unsafe categories reference
  • Get full PR diff
  • Analyze diff against all unsafe categories
  • Apply label

Result: ✅ Safe to Roll Back

Changes analyzed:

File Change
dot-key-value-table-header-row.component.ts Added effect import and a constructor with effect(() => { this.$forbiddenkeys(); this.keyControl.updateValueAndValidity({ emitEvent: false }); })
dot-key-value-table-header-row.component.spec.ts Added one regression test

Verdict against every unsafe category:

Category Match?
C-1 Structural Data Model Change ✅ No — pure UI component
C-2 Elasticsearch Mapping Change ✅ No
C-3 Content JSON Model Version Bump ✅ No
C-4 DROP TABLE / DROP COLUMN ✅ No
H-1 One-Way Data Migration ✅ No
H-2 RENAME TABLE / RENAME COLUMN ✅ No
H-3 PK Restructuring ✅ No
H-4 New Content Type Field Type ✅ No
H-5 Binary Storage Provider Change ✅ No
H-6 DROP PROCEDURE / DROP FUNCTION ✅ No
H-7 NOT NULL Column Without Default ✅ No
M-1 Non-Broadening Column Type Change ✅ No
M-2 Push Publishing Bundle Format Change ✅ No
M-3 REST / GraphQL API Contract Change ✅ No — Angular-internal form validation only
M-4 OSGi Plugin API Breakage ✅ No

This PR touches only an Angular UI component and its test. No database migrations, Elasticsearch mapping changes, REST/GraphQL contract modifications, or backend code of any kind are involved. Rolling back to N-1 has zero risk.

@github-actions github-actions Bot added the Area : Frontend PR changes Angular/TypeScript frontend code label Apr 24, 2026
@adrianjm-dotCMS adrianjm-dotCMS marked this pull request as ready for review April 24, 2026 19:50
Copilot AI review requested due to automatic review settings April 24, 2026 19:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a reactive-forms validation staleness bug in the Key/Value UI component so that the “duplicate key” error is cleared when the conflicting key is removed from the forbidden-keys map (e.g., after deleting an entry).

Changes:

  • Added an Angular effect() in DotKeyValueTableHeaderRowComponent to re-run key validation whenever the forbiddenkeys signal input changes.
  • Added a regression unit test verifying the duplicatedKey error is cleared after forbiddenkeys is updated.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-header-row/dot-key-value-table-header-row.component.ts Revalidates the key control when forbiddenkeys changes by triggering updateValueAndValidity() inside an effect().
core-web/libs/ui/src/lib/components/dot-key-value-ng/dot-key-value-table-header-row/dot-key-value-table-header-row.component.spec.ts Adds a regression test ensuring duplicatedKey is cleared when the conflicting key is removed from forbiddenkeys.

@adrianjm-dotCMS adrianjm-dotCMS added this pull request to the merge queue Apr 24, 2026
Merged via the queue into main with commit 0781bfd Apr 24, 2026
34 checks passed
@adrianjm-dotCMS adrianjm-dotCMS deleted the 32114-key-value-validation-refresh branch April 24, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Safe To Rollback Area : Frontend PR changes Angular/TypeScript frontend code

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Key/Value Field: Key validation does not refresh after deleting conflicting key/value pair

4 participants