Skip to content

Fix dynamic form collection reset and parameter uniqueness validation - #1552

Closed
LMatt08 wants to merge 2 commits into
Part-DB:masterfrom
LMatt08:fix/form-collection-reset
Closed

LMatt08 wants to merge 2 commits into
Part-DB:masterfrom
LMatt08:fix/form-collection-reset

Conversation

@LMatt08

@LMatt08 LMatt08 commented Sep 19, 2026

Copy link
Copy Markdown

Summary

This PR fixes two issues affecting dynamic form collections:

  • Restore the initial collection structure when a form is reset, including rows removed or added after the initial page load.
  • Properly unregister the TomSelect form-reset listener when an instance is destroyed.
  • Ignore parameters no longer present in their owning Part collection during uniqueness validation. This allows removing a parameter and recreating it with the same name in a single form submission, while still rejecting two simultaneously active parameters with the same name.

These generic changes were extracted from #1492 following review feedback. This PR contains no parameter-definition, choice-list, filtering, migration, or permission changes.

Implementation

The changes are split into two commits:

  1. Fix resetting dynamic form collections

    • Restores the initial collection structure on form reset.
    • Cleans up the registered reset listener when TomSelect is destroyed.
  2. Ignore removed parameters during uniqueness validation

    • Adds a dedicated repository method used by the UniqueEntity constraint.
    • Considers only parameters still present in the owning Part collection.
    • Adds focused regression tests independent of the parameter-definition feature.

Verification

A negative-control run against the unmodified upstream/master reproduced the issue:

Tests: 2, Assertions: 3, Failures: 1
testRemovedParameterCanBeRecreatedWithTheSameNameBeforeFlush
ERROR: This value is already used.

With the changes applied:

Focused regression tests: 2 tests, 9 assertions — OK
PartParameterTest + PartControllerTest: 46 tests, 72 assertions — OK
PHPStan targeted analysis: OK
ESLint targeted analysis: OK
Yarn production build: OK
git diff --check: OK

The repository currently has no DOM/browser test infrastructure for the JavaScript reset behavior, so the modified JavaScript was verified through ESLint and the production asset build.

jbtronics added a commit that referenced this pull request Sep 20, 2026
This has the same effect as PR #1552 but uses a much more generic approach which can be easily used for other entities
@jbtronics

Copy link
Copy Markdown
Member

Thanks for the PR.

I cherry picked the form reset commit.
For the parameter uniquness validation, i implemented a far more generic approach, which implements a custom #[UniqueEntityIgnoringOrphans(fields: ['name', 'group', 'element'], ownerField: 'element')] validator, which just uses doctrine metadata to check that automatically, without the need of a custom repo function.
This can be easily applied to both parameters and attachments for all element types.

@jbtronics jbtronics closed this Sep 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants